Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Gradle run two tests in a specific order?

We're migrating some ant build scripts to gradle and are diagnosing issues along the way. One problem that has popped up is that on the CI server (jenkins running gradle) we occasionally get test failures. We think the issue is related to test execution order because one of the tests that is failing uses thread local storage in some library code.

I would like to be able to reproduce the problem locally before fixing the broken tests. However. I can't reproduce the problem locally because gradle always runs the tests in an order that happens to work.

So, is there a way to force gradle to run test class X before test class Y? The tests need to run in the same JVM - one test right after the other.

In case it matters, the tests are JUnit tests.

like image 841
clucas Avatar asked Oct 23 '13 21:10

clucas


2 Answers

Yes, it is possible. One of the possibilities is to create additional task for test Y run

task YTest(type: Test) {
    include '**/Y.*'
}

test {
    exclude '**/Y.*'
}

test.dependsOn YTest
like image 102
Roman Konoval Avatar answered Sep 24 '22 23:09

Roman Konoval


Per Peter's response on the gradle forum, this is not possible.

http://forums.gradle.org/gradle/topics/can_gradle_run_two_tests_in_a_specific_desired_order_in_the_same_jvm?utm_content=reply_link&utm_medium=email&utm_source=reply_notification#reply_13187620

An alternative is to use a test suite.

like image 23
clucas Avatar answered Sep 23 '22 23:09

clucas