Is there an extension for JUnit4 which allows for marking some tests as "expected to fail"?
I would like to mark the test for current features under development with some tag, for instance @wip. For these tests I would like to ensure that they are failing.
My acceptance criteria:
Scenario: A successful test tagged @wip is recorded as failure
Given a successful test marked @wip
When the test is executed
Then the test is recorded as failure.
Scenario: A failing test tagged @wip is recorded as fine
Given a failing test tagged @wip
When the test is executed
Then the test is recorded as fine.
Scenario: A successful test not tagged @wip is recorded as fine
Given a successful test not tagged @wip
When the test is executed
Then the test is recorded as successful.
Scenario: A failing test not tagged with @wip is recorded as failure
Given a failing test not tagged with @wip
When the test is executed
Then the test is recorded as failure.
Short answer, no extension will do that as far as I know and in my opinion it would defeat the whole purpose of JUnit if it would exist.
Longer answer, red/green is kind of sacred and circumventing it shouldn't become a habit. What if you accidentally forgot to remove the circumvention and assume that all tests passed?
You could make it expect an AssertionError
or Exception
.
@wip
@Test(expected=AssertionError.class)
public void wipTest() {
fail("work in progress");
}
Making a shortcut in your IDE for that shouldn't be too hard. Of course I was assuming you tag the test with an annotation in the source code.
In my opinion what you are asking is against JUnit's purpose, but I do understand the use for it.
An alternative would be to implement a WIPRunner
with the WIP
annotation and somehow make it accept failures of tests with the WIP
annotation.
If you are integrating with a BDD framework I would suggest a way to let it run the unit tests you marked @wip seperately and decide within your BDD methods if the result is ok.
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