Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Junit throw warning while still passing test

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.

like image 405
Josh Bones Avatar asked Aug 05 '09 00:08

Josh Bones


2 Answers

Would org.junit.Assume do what you need?

like image 67
lumpynose Avatar answered Sep 30 '22 17:09

lumpynose


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.

like image 27
Christian Hang-Hicks Avatar answered Sep 30 '22 18:09

Christian Hang-Hicks