Test - from maven to gradle

Hello,

I’m trying to migrate some integration test from maven to gradle, and I’ve a few questions.

After reading the gradle documentation, I transformed this

<profile>
      <id>integration-tests</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.13</version>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <forkMode>always</forkMode>
              <argLine>-Xmx1024m -XX:MaxPermSize=512m -XX:-UseSplitVerifier</argLine>
              <includes>
                <include>**/*IntegrationTest.java</include>
              </includes>
              <excludes>
                <exclude>com/.../test/*IntegrationTest.java</exclude>
              </excludes>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>7.5.2.v20111006</version>
            <configuration>
              <webAppConfig>
                <contextPath>/xsa-pom</contextPath>
              </webAppConfig>
              <scanIntervalSeconds>10</scanIntervalSeconds>
              <stopKey>foo</stopKey>
              <systemProperties>
                <systemProperty>
                  <name>jetty.port</name>
                  <value>9099</value>
                </systemProperty>
              </systemProperties>
              <stopPort>9090</stopPort>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>ch.finnova</groupId>
          <artifactId>edbs6</artifactId>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>cronto</groupId>
          <artifactId>crontoengine</artifactId>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

to this (inside subproject{})

test {
		useJUnit()

		// show standard out and standard error of the test JVM(s) on the console
		testLogging.showStandardStreams = true

		// explicitly include or exclude tests
		include '**/*IntegrationTest.java'
		exclude 'com/.../test/*IntegrationTest.java'

		// set heap size for the test JVM(s)
		minHeapSize = "Xms256m"
		maxHeapSize = "Xmx768m"

		// set JVM arguments for the test JVM(s)
		jvmArgs '-Xmx1024m', '-XX:MaxPermSize=512m', '-XX:-UseSplitVerifier'

		// listen to events in the test execution lifecycle
		beforeTest { descriptor ->
			logger.lifecycle("Running test: " + descriptor)
		}

		// listen to standard out and standard error of the test JVM(s)
		onOutput { descriptor, event ->
			logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
		}
	}

Is it correct?

I receive compilation errors like

required: Class<? extends Runner> found: Class<SpringJUnit4ClassRunner>

But I don’t understand if it is related to some error in the gradle script or not. I think yes because with maven the tests run fine

Thank you very much

Looks like you are missing a dependency. IMO Gradle tries to use something which is built in. Did you added all dependencies from Maven to Gradle when migrated?

Note: Gradle comes with some libraries which can conflict with your dependencies if are older/newer. I will advise you to use either -d or -S to detect the problem in your script.

Is there a way to add dependencies to the test and not to the rest of the projects?

In the subproject’s build file I have the testCompile: “…” and I thought it was enough

testCompile and testRuntime is what you are looking for. If you are in multi-project setup divide configurations per project. Place them only where tests are.

subprojects is wrapping all sub-projects (described in settings.gradle). I think is not good idea to place “global” dependency there.

Ok, I was doing exactly the same thing and it works :slightly_smiling: