Test - from maven to gradle


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

              <argLine>-Xmx1024m -XX:MaxPermSize=512m -XX:-UseSplitVerifier</argLine>

to this (inside subproject{})

test {

		// 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: