我有一个包含一个包含4种测试方法的类的测试项目,我并行运行这些测试,在testng.xml中为同一类创建4个不同的类,还对POM> Surefire插件部分进行了必填项。
现在,问题是....
步骤1:如果我右键单击POM.xml并以“ Maven测试”运行,我会看到以下结果(不正确)
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.parallel</groupId>
<artifactId>DemoFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>
<suiteXmlFiles>testng.xml</suiteXmlFiles>
<skipTests>false</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.clerezza.ext</groupId>
<artifactId>org.json.simple</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0-atlassian-hosted</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.zeroturnaround/zt-zip -->
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-zip</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/mvn/maven-external/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
</repository>
</repositories>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>qa</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>qa</env>
</properties>
</profile>
<profile>
<id>offline</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<env>offline</env>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<verbose>true</verbose>
<filesets>
<fileset>
<directory>test-output</directory>
<directory>target</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<verbose>false</verbose>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>transform</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete
file="${project.build.outputDirectory}/environment.properties" />
<copy
file="src/main/resources/environment.${env}.properties"
tofile="${project.build.outputDirectory}/environment.properties" />
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
<execution>
<id>start</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<skipTests>${skipTests}</skipTests>
<suiteXmlFiles>${suiteXmlFiles}</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] com.test.parallel.tests.SampleTest.beforeMethod
[ERROR] Run 1: SampleTest>BaseTest.beforeMethod:49 » Runtime Simulating configuration failure
[ERROR] Run 2: SampleTest>BaseTest.beforeMethod:49 » Runtime Simulating configuration failure
[ERROR] Run 3: SampleTest>BaseTest.beforeMethod:49 » Runtime Simulating configuration failure
[ERROR] Run 4: SampleTest>BaseTest.beforeMethod:49 » Runtime Simulating configuration failure
[INFO]
[INFO]
[ERROR] **Tests run: 12, Failures: 1, Errors: 0, Skipped: 1**
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.589 s
[INFO] Finished at: 2020-01-16T19:12:16+05:30
[INFO] ------------------------------------------------------------------------
第2步:如果我右键单击testng.xml并以“ TestNG Suite”身份运行,则会看到以下结果(正确)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" thread-count="32" parallel="methods">
<listeners>
<listener
class-name="com.test.parallel.selenium.TestExecutionListener"></listener>
<listener
class-name="com.test.parallel.selenium.TestNGReportListener"></listener>
</listeners>
<test name="chrome1">
<parameter name="browser" value="chrome" />
<parameter name="server"
value="http://127.0.0.1:4723/wd/hub" />
<classes>
<class name="com.test.parallel.tests.SampleTest" />
</classes>
</test>
<test name="firefox1">
<parameter name="browser" value="forefox" />
<parameter name="server"
value="http://127.0.0.1:4723/wd/hub" />
<classes>
<class name="com.test.parallel.tests.SampleTest" />
</classes>
</test>
<test name="chrome2">
<parameter name="browser" value="chrome" />
<parameter name="server"
value="http://127.0.0.1:4723/wd/hub" />
<classes>
<class name="com.test.parallel.tests.SampleTest" />
</classes>
</test>
<test name="firefox2">
<parameter name="browser" value="forefox" />
<parameter name="server"
value="http://127.0.0.1:4723/wd/hub" />
<classes>
<class name="com.test.parallel.tests.SampleTest" />
</classes>
</test>
</suite>
> ===============================================
> Suite Total tests run: 16, Passes: 12, Failures: 0, Skips: 4
> Configuration Failures: 4,
> Skips: 0
> ===============================================
步骤1中报告的结果不同于步骤2。如您所见,我的测试总数应为16,而跳过(配置失败)为4,通过为12。但是Surefire报告它们不正确,总数为12,而失败为1,跳过为1,总计仅14。
这不正确吗?还是我误解了结果?如何获得Maven Surefire插件来报告与TestNG结果相同的正确结果。
感谢您的投入。