Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle equivalent of Surefire classpathDependencyExclude

I'm trying to migrate java project from maven to gradle. The problem is very tricky classpath dependency configuration for tests now.

Our maven-surefire-plugin configuration:

 <includes>
     <include>**/SomeTest1.java</include>
 </includes>
 <classpathDependencyExcludes>
     <classpathDependencyExclude>com.sun.jersey:jersey-core</classpathDependencyExclude>
 </classpathDependencyExcludes>

There are different classpathes for different test-classes. How can I implement it with Gradle?

like image 847
Max Kraynov Avatar asked Aug 25 '15 15:08

Max Kraynov


People also ask

How do I create a test report in gradle?

How to generate a Test Report. Gradle generates a Test Report automatically when it runs the entire Test Suite. To do the same, run ./gradlew test (or gradlew. bat test from Windows), or run the test Gradle task from your IDE.

Does gradle run tests in parallel?

Parallel execution Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.

How do I run a gradle test from the command line?

Use the command ./gradlew test to run all tests.

How do you read a surefire report?

The Surefire Report Plugin parses the generated TEST-*. xml files under ${basedir}/target/surefire-reports and renders them using DOXIA, which creates the web interface version of the test results. New interprocess communication and TCP/IP which fixes current blocker and critical bugs.


2 Answers

First of all you need to differ your tests sources into separate sourceSets. Say, we need to run tests from package org.foo.test.rest with a little different runtime classpath, than other tests. Thus, its execution will go to otherTest, where remain tests are in test:

sourceSets {
    otherTest {
        java {
            srcDir 'src/test/java'
            include 'org/foo/test/rest/**'
        }
        resources {
            srcDir 'src/test/java'
        }
    }
    test {
        java {
            srcDir 'src/test/java'
            exclude 'org/foo/rest/test/**'
        }
        resources {
            srcDir 'src/test/java'
        }
    }
}

After that, you should make sure that otherTest has all required compile and runtime classpaths set correctly:

otherTestCompile sourceSets.main.output
otherTestCompile configurations.testCompile
otherTestCompile sourceSets.test.output
otherTestRuntime configurations.testRuntime + configurations.testCompile

The last thing is to exclude (or include) unneeded runtime bundles from test:

configurations {
    testRuntime {
        exclude group: 'org.conflicting.library'
    }
}

And to create Test Gradle task for otherTest:

task otherTest(type: Test) {
    testClassesDir = sourceSets.otherTest.output.classesDir
    classpath += sourceSets.otherTest.runtimeClasspath
}

check.dependsOn otherTest
like image 165
Artem Dmitriev Avatar answered Sep 18 '22 09:09

Artem Dmitriev


Use next workaround:

  1. Create source set for needed tests
  2. Add configurations for created sourceSet
  3. Add task for run test with custom configuration
  4. Configure test task dependOn customized test task
  5. Configure Report plugin for generate beautiful html report :)

Like this getting started

like image 20
Kirill Tolkachev Avatar answered Sep 17 '22 09:09

Kirill Tolkachev