Java TestNG在无法实例化测试时跳过测试
我知道TestNG配置了FailurePolicy标志,以便在@Before方法中出现错误时继续测试。但是,当一个测试出错时,有没有办法继续运行其余的测试呢。。比如说在测试类实例化过程中出现了一些异常 是否可以将此报告为错误并使生成失败 这是我的考试课Java TestNG在无法实例化测试时跳过测试,java,maven,testng,Java,Maven,Testng,我知道TestNG配置了FailurePolicy标志,以便在@Before方法中出现错误时继续测试。但是,当一个测试出错时,有没有办法继续运行其余的测试呢。。比如说在测试类实例化过程中出现了一些异常 是否可以将此报告为错误并使生成失败 这是我的考试课 public class MyTest { public MyTest() { throw new RuntimeException(); } @Test public void testMethod1() { ...
public class MyTest {
public MyTest() {
throw new RuntimeException();
}
@Test
public void testMethod1() {
...
}
@Test
public void testMethod2() {
...
}
}
public class MyTest2 {
@Test
public void testMethod1() {
...
}
@Test
public void testMethod2() {
...
}
}
现在,我通过Maven运行这些测试:
mvn clean test
输出:
Running Test Suite
....
Cause by: org.testng.TestNGException
Cannot instantiate class ...MyTest1
....
Cause by: java.lang.RuntimeException:
....
Results:
Tests run: 0, Failed: 0, Errors: 0, Skipped: 0
....
--------------
Build Success
--------------
Total time: ..
Maven pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>...</groupId>
<artifactId>...</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>XYZ</name>
<dependencies>
....
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>${basedir}/target/site</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.4.1</version>
</plugin>
</plugins>
</reporting>
</project>
您能显示您的pom文件吗?在问题中添加了pom文件。您有testng.xml文件吗?没有,我没有使用testng.xml文件