Using Gradle with Java and TestNG and having following problem - I have a class, which has BeforeSuite annotation, but it is not executed.
public class BaseUITest {
@BeforeSuite(alwaysRun = true)
public void setUp(){
System.out.println("BaseUITest");
}
}
public class TestLogin extends BaseUITest {
@Test
public void correctLogin() {
System.out.println("correctLogin");
}
}
In testng.xml I have following:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
<test name="Regression">
<classes>
<class name="com.example.com.ui.tests.TestLogin"/>
</classes>
</test>
</suite>
And in build.gradle in module:
plugins {
id 'java'
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
repositories {
mavenCentral()
}
ext {
testNgVersion = '6.14.3'
}
dependencies {
testCompile "org.testng:testng: $testNgVersion"
}
test {
useTestNG(){
suites 'src/test/resources/testng.xml'
}
}
And in main build.gradle:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2"
}
}
}
subprojects {
apply plugin: 'java'
repositories {
jcenter()
}
}
In console I see only “correctLogin”, but there is no “BaseUITest”.
If I remove line suites 'src/test/resources/testng.xml'
from build.gradle in the module, test runs Ok, BeforeSuite is executed.
Tried to add groupByInstances = true
and preserveOrder true
in build.gradle file in the module - it doesn’t help.