I am creating a Gradle project to be used in conjunction with TestNG. So far, I am running the TestNG file, structured in this form, to run tests:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
<test name="Test">
<classes>
<class name="package1.class1"></class>
<class name="package2.class2"></class>
</classes>
</test>
</suite>
What I'd like to do is to have the Gradle build file do the same thing as what I am currently doing when I run this testng.xml file (i.e. run class 1's test suite, and then class 2's suite). After doing a little searching, my build.gradle file currently looks like this:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
// add the dependencies as needed
testCompile group: 'org.testng', name: 'testng', version:'6.9.10'
testCompile fileTree('lib')
}
test {
useTestNG() {
// Run the test suite textng.xml, which is in the same directory.
suites 'testng.xml';
include '**/*package1.class1.*'
include '**/*package2.class2.*'
}
}
...and my settings.gradle file like this:
include 'shared'
include 'api'
include 'services:webservice'
rootProject.name = 'Project1'
When I run with this configuration, however, the tests do not run as expected. What am I missing from this code?
EDIT: After doing some more digging, I decided to try running TestNG directly from Gradle, creating a new testng.xml file:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
// Add any necessary dependencies.
testCompile group: 'org.testng', name: 'testng', version:'6.9.10'
testCompile fileTree('lib')
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
}
task runTests(type: JavaExec, dependsOn: 'classes') {
classpath = files("${projectDir}/src", project.sourceSets.main.compileClasspath,
project.sourceSets.test.compileClasspath,
project.sourceSets.main.runtimeClasspath,
project.sourceSets.test.runtimeClasspath)
main = 'org.testng.TestNG'
args = ["-parallel", "methods", "-threadcount", "1", "-d", "./build/test-output", "testng.xml"]
}
I think both approaches could potentially go somewhere, except that, even though I've included the location of my source directory, I'm still getting this error:
Cannot find class in classpath: package1.class1