Run Gradle JUnit test in particular order

I’ve tried to search for a solution to run gradle JUnit tests in specific order, and here is the easy solution.

For example, you want to initialize the test data before running any test, just specify the following include filters in build.gradle.

apply plugin: "java"
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'


repositories {

dependencies {
    compile project(':common')
    compile sharedDependencies.spring.context
    compile sharedDependencies.spring.contextsupport
    compile sharedDependencies.spring.dataMongo
    compile (sharedDependencies.dozer) {
        exclude group: "org.slf4j", module: "slf4j-log4j12"
    compile sharedDependencies.commons.lang
    compile sharedDependencies.validation.oval
    compile sharedDependencies.jackson.annotations
    compile sharedDependencies.swagger.annotations
    compile sharedDependencies.mail.javamail
    compile sharedDependencies.velocity
    compile sharedDependencies.ehcache

    testCompile sharedDependencies.junit
    testCompile sharedDependencies.spring.test

jar {
    from sourceSets.main.allJava

//load InitData.class first before running any other unit testing
    include "**/InitData.class"
    include "**/*Test.class"



(Visited 48 times, 1 visits today)

Leave a Reply