0

I would like to stop and mark as failed too long running junit tests (executed within Maven 3 build). I am aware of three ways of doing it:

1) Using Test annotation with timeout parameter:

@Test(timeout=100)
public void testWithTimeout() {
    ...
}

2) Using Rule annotation:

@Rule
public Timeout globalTimeout = new Timeout(100);

3) Configuring maven-surefire-plugin using following options:

forkedProcessTimeoutInSeconds=1
reuseForks=false

The clue is 1) and 2) requires to change each test (it hurts when you have many thousands). 3) solution is not acceptable as within many modules first test starts the context which is used by the test - tests performance would drastically decrease.

Do you have any other ideas how to achieve that? Any tricky solution (not involving patching JUnit :))?

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by ~s.o.s~
0

AFAIK you can attach rules to Test suites. So all you would need to do is "group" your tests logically into suites based on whether they need a timeout or not and then apply a timeout rule to the suite.

Or you can create a parent class for performance sensitive tests with a particular timeout rule and make sure all tests which need to follow a particular timeout extend this parent class.

Not ideal but much better than adding timeouts to each and every test...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.