Why we have to specify useTestNG() for tests with Gradle?
Asked Answered
C

1

7

If we want to use for our test TestNG we have to write something like:

dependencies {
   compile project(':model')
   testCompile 'org.testng:testng:6.8'
}

test.useTestNG()

But when using Spock we specify just the dependency

dependencies {
   compile project(':model')
   testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
}

Why we have to specify test.useTestNG()?

Courthouse answered 23/7, 2014 at 11:28 Comment(0)
S
7

Spock tests get run via JUnit, which is the Gradle default. Alternatively, tests can be run via TestNG.

Sarcomatosis answered 23/7, 2014 at 11:34 Comment(5)
So test.useTestNG() is used to change the default Gradle test framework? Now I checked that there is test.useJUnit() why is this needed if JUnit is the default?Courthouse
useJUnit { ... } is only needed if JUnit-specific options need to be configured. useTestNG() is needed to switch to TestNG, and also to configure TestNG-specific options.Sarcomatosis
Thank, but I will continue with stupid questions (blush) if we want to use TestNG, JUnit and Spock at the same time? How to tell Gradle to use them at the same time if I write useJunit,useTestNG, the second will be the last configuration which will be taken into account?Courthouse
You need separate Test tasks for that.Sarcomatosis
Something like task testNGTask(type: Test) { useTestNG() } Thanks.Courthouse

© 2022 - 2024 — McMap. All rights reserved.