Rafay
Rafay

Reputation: 92

How to override a Timeout @Rule for a specific test which takes longer than all other tests

I have a rule defined in my junit test base class, but one of test in one of the extended class takes much longer time, and i was wondering if there is a good practice to follow here to cover this case?

Can i simply provide a timeout to that test and will that override the timeout rule like:

@Test(timeout = 3600000)
public void testLongTimeout() throws Exception { ... }

Or is there a better way of doing this? I was also thinking to move that single test out of that class into its own class and overriding the timeout rule for that. Suggestions?

Upvotes: 1

Views: 390

Answers (1)

ttzn
ttzn

Reputation: 2613

The timeout attribute of a @Test and the Timeout rule are both applied independently. So what will happen if you combine the two is that the lower value will prevail. Putting the offending test in its own class with its own rule, as you proposed, is probably the best solution.

Upvotes: 1

Related Questions