[英]BeforeGroups method is not executed when running testng tests by maven
I see that the method marked with "@BeforeGroups" is not executed by .我看到标有“@BeforeGroups”的方法不是由 .
Java test class: 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());
}
}
in the same package - the class to configure server:在同一个包中 - 配置服务器的类:
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 file: 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>
running:跑步:
mvn integration-test mvn 集成测试
[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
From Maven Failsafe Plugin – Inclusions and Exclusions of Tests :来自Maven 故障安全插件 - 测试的包含和排除:
By default, the Failsafe Plugin will automatically include all test classes with the following wildcard patterns:
默认情况下,Failsafe 插件将自动包含所有具有以下通配符模式的测试类:
"**/IT*.java"
- includes all of its subdirectories and all Java filenames that start with "IT"."**/IT*.java"
- 包括其所有子目录和所有以“IT”开头的 Java 文件名。"**/*IT.java"
- includes all of its subdirectories and all Java filenames that end with "IT"."**/*IT.java"
- 包括其所有子目录和所有以“IT”结尾的 Java 文件名。"**/*ITCase.java"
- includes all of its subdirectories and all Java filenames that end with "ITCase"."**/*ITCase.java"
- 包括其所有子目录和所有以“ITCase”结尾的 Java 文件名。
As the TestServerConfigurator
class name does not match any of the default inclusion patterns it is being excluded from your test run.由于
TestServerConfigurator
类名与任何默认包含模式都不匹配,因此它被从您的测试运行中排除。
You can rename TestServerConfigurator
to something that matches the default patterns (ie ITTestServerConfigurator
, TestServerConfiguratorIT
, or TestServerConfiguratorITCase
) or define your own inclusion patterns:您可以将
TestServerConfigurator
重命名为与默认模式匹配的内容(即ITTestServerConfigurator
、 TestServerConfiguratorIT
或TestServerConfiguratorITCase
)或定义您自己的包含模式:
<configuration>
<includes>
<include>**/*IT.java</include>
<include>**/*Configurator.java</include>
</includes>
<groups>http</groups>
</configuration>
I see it works if I replace "configuration" section with this:如果我用这个替换“配置”部分,我看到它有效:
<configuration>
<groups>http</groups>
<includes>
<include>*</include>
</includes>
</configuration>
I thought "includes" section was intended to list tests only and not all classes that should be visible to testng, but apparently that's not the case.我认为“包含”部分旨在仅列出测试而不是所有应该对 testng 可见的类,但显然情况并非如此。
Faced with the same problem.面临同样的问题。 Add
@Test(groups = "http")
to your TestServerConfigurator
class将
@Test(groups = "http")
到您的TestServerConfigurator
类
尝试根据您的系统浏览器更新ChromeDriver
版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.