Reputation: 830
I have a problem with JUnit4 and it's @Test(timeout=xxx)
annotation. For example, two tests with same body, different name. None of them uses any global variables which can be initialized.
When I run tests it has totally different execution time (First test 0,811s, second 0,143).
It's very important for me to get similar results. Is there any way to resolve/workaround this problem ?
Upvotes: 0
Views: 165
Reputation: 4895
Try using a timeout rule instead. The class will have been initialized before the timeout rule is applied, so class initialization time should be excluded.
Upvotes: 0
Reputation: 32949
It is probable that the first test is reported as having taken longer because this includes the setup time JUnit takes to initialize the class. If you have 2 tests that need to run in approximitely the same amount of time, consider adding a third test before the other two just to get the init stuff out of the way.
Let me know if this works, am curious.
Upvotes: 1