Issue
For my espresso tests, I am searching for a way to let all tests fail before they run, if a specific condition is not met. How can I achieve this?
Solution
How about creating a jUnit rule to handle that? Specifically the Verifier rule. https://github.com/junit-team/junit4/wiki/rules#verifier-rule
Verifier is a base class for Rules like ErrorCollector, which can turn otherwise passing test methods into failing tests if a verification check is failed.
private static String sequence;
public static class UsesVerifier {
@Rule
public final Verifier collector = new Verifier() {
@Override
protected void verify() {
sequence += "verify ";
}
};
@Test
public void example() {
sequence += "test ";
}
@Test
public void verifierRunsAfterTest() {
sequence = "";
assertThat(testResult(UsesVerifier.class), isSuccessful());
assertEquals("test verify ", sequence);
}
}
Answered By - Szymon K.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.