I'm working on a project at the moment that we're using junit to test, but as its still fairly early stages a lot of features aren't yet implemented, though they already have tests written for them
this means these tests (obviously) always fail
I was wondering if anyone knew a way to get JUnit to pass the test while displaying a warning. preferably with a customizable message so we can note that the feature is not yet implemented.
The point of this being that we want to code to compile only if all tests pass, and at the moment this simply isn't possible.
I realise we can just comment out or remove the problem tests, but we then run the risk of forgetting to add them back in later.
Would org.junit.Assume do what you need?
Most JUnit runners I've seen will give you one of four statuses for a test case: passed, failed, had errors or ignored.
As had errors (threw an Exception) is reported in a similar fashion as failed ("red result") there isn't a good way to generate a warning and still have a "green result" - I assume that is what you are looking for?
As mentioned by Janusz, you can use the @Ignore
attribute to ignore a test case which can contain a message as well:
@Ignore("disabled until implementation is finished")
public void testMe() {
//do something
}
Most runners will not list them explicitely in the results, but you are able to look for any ignored test cases automatically using tools, by looking for the @Ignore
attribute and generate a report afterwards, which lists all test cases which have been skipped and the reason (given in the attribute) why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With