Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running two test classes in sequence while using gradle --parallel to run the tests

Tags:

junit

gradle

We have two different test classes (each contains several test methods), they may affect each other while running in parallel and in the same jvm process. I know this sounds bad, but currently we have no easy solution to separate those two test classes.

How to specify the running order of these two test classes (to make them run in sequennce) while I still want the parallel test execution using gradle --parallel? Thanks a lot in advance.

[UPDATE]:

I have the following configurations

test {
// maxParallelForks=8
testLogging.showStandardStreams=true

    exclude '**/ATests.scala'
    exclude '**/BTests.scala'
}

task runATests(type: Test) {
    include '**/ATests.scala'
}

task runBTests(type: Test) {
    include '**/BTests.scala'
}

How can I verify that ATests and BTests are actuall run in different test JVM, from the logs, it seems have no related information about this? Thanks

like image 580
chuchao333 Avatar asked Mar 24 '23 04:03

chuchao333


1 Answers

The problem isn't related to parallel task or test execution (which, by the way, are independent Gradle features) because Gradle runs tests in a single thread per test JVM. The problem is simply that multiple tests access the same singleton and invalidate each other's expectations of that object's initial state. Possible solutions:

  • Make each affected test reset the singleton to a known state.
  • Make sure that each affected test is executed by a different Test task (and hence runs in a different test JVM).
  • Get rid of the singleton.
like image 94
Peter Niederwieser Avatar answered Mar 26 '23 15:03

Peter Niederwieser