0

I have to fix a legacy code where 2 JUNITS classes are running in parallel and thats why interfering with each others results.

Now, looking at the legacy code, I want to keep the changes to the minimum.

The best I could think of is to let these 2 classes execute sequentially and one after the another. I dont want to make all JUNITS to execute sequentially just because of these 2.

Is there any way to achieve this in JUNIT.

All annotations I could find are dealing with sequence of JUNIT method and not the classes. Not able to find annotations for class sequence.

Onki
  • 1,879
  • 6
  • 38
  • 58
  • 2
    have you thought about using a Test Suite to group both the classes? – sudipn Dec 09 '19 at 17:38
  • Do both tests act on the same code or does the production code units share a common resource (and what type of resource is this)? – Timothy Truckle Dec 09 '19 at 19:23
  • My advice - which you probably won't follow - would be to consider to just `@ignore` the tests... 2 tests that are dependent on each other are clearly not *isolated* which reeks like a smell... – Ward Dec 09 '19 at 20:07
  • @Ward that should only be the last resort if nothing else works. – Timothy Truckle Dec 09 '19 at 20:23
  • 1
    Don't agree. *Sometimes* no tests are better than shitty tests. E.g. the kind of tests that rather fails because the test is wrong rather than the production code containing a bug... Not saying this is the case here, (I can't possibly know). But I think it is always a good idea to _consider_ if a problem is worth fixing... – Ward Dec 09 '19 at 20:40
  • @sudipn i had similar issue and tried grouping them in a suite. but still it did not run sequentially. any other ideas? – DecKno Jan 17 '20 at 16:40
  • check here: https://stackoverflow.com/questions/42599565/execute-order-for-test-suite-in-junit – sudipn Jan 19 '20 at 20:57
  • so here is how I solved this issue : as the test runs alone successfully and upon running it together they fails, so I started running that test class by copying it to all available packages (generally at higher level we have approx 10-20 packages), and I saw it was failing with one. Then I ran with subpackeges, and thats how I tracked it to class and test which was causing the failure. they were using some common data strcuture which was supposed to be initialized only once. fixed and moved on :-) – Onki Feb 02 '20 at 09:56

0 Answers0