Reputation: 1105
Why the name of a test method may influence other tests?
I have a suite with 2 classes of tests, and when I change a method name of class1, my test in class2 is ok (green).
I noticed that both classes have a method with the same name, but the test that is failing is neither of these. However if I rename any of them, all tests are ok.
Is it okay to have 2 methods with the same name in different classes, but in the same suite? And the fact that another test fails randomly is just a coincidence?
ps: the order of tests runned is changed after I rename that method. ps2: sorry for my bad English.
That picture can explain better my question:
Upvotes: 8
Views: 2705
Reputation: 5629
There is no bug in JUnit! Our team experienced similar results, which are caused by inproper resource management. You can try to rename your failing test so they are executed first. They should turn green now, that's mostly a sign that a resource is accidently shared between tests. In that case you can try to free the resource in the tear down (@After
).
Here is a little checklist to find the cause:
Upvotes: 10