Я вижу, что метод, помеченный знаком «@BeforeGroups», не выполняется.Метод BeforeGroups не выполняется при выполнении тестов testng по maven
Java тестовый класс:
import org.testng.annotations.Test;
import static org.testng.Assert.fail;
@Test(groups = "http")
public class MyIT {
@Test(groups = "http")
public void method1() {
System.out.println("test 1 - value from TestServerConfigurator: "
+ TestServerConfigurator.getSomeString());
}
}
в том же пакете - класс для настройки сервера:
public class TestServerConfigurator {
private static String someString;
@BeforeGroups(groups = "http")
public static void init() {
System.out.println("initializing server...");
someString = "value set!";
}
@AfterGroups(groups = "http")
public static void after() {
System.out.println("stopping server...");
}
public static String getSomeString() {
return someString;
}
}
pom.xml файл:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.alskor</groupId>
<artifactId>mytests</artifactId>
<version>1.0-SNAPSHOT</version>
<name>mytests</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<groups>http</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
бега:
МВН интеграции тест
[INFO] --- maven-failsafe-plugin:2.19.1:integration-test (default) @ mytests ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running MyIT
test 1 - value from TestServerConfigurator: null
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.218 sec - in MyIT
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0