Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java TestNG在无法实例化测试时跳过测试_Java_Maven_Testng - Fatal编程技术网

Java TestNG在无法实例化测试时跳过测试

Java TestNG在无法实例化测试时跳过测试,java,maven,testng,Java,Maven,Testng,我知道TestNG配置了FailurePolicy标志,以便在@Before方法中出现错误时继续测试。但是,当一个测试出错时,有没有办法继续运行其余的测试呢。。比如说在测试类实例化过程中出现了一些异常 是否可以将此报告为错误并使生成失败 这是我的考试课 public class MyTest { public MyTest() { throw new RuntimeException(); } @Test public void testMethod1() { ...

我知道TestNG配置了FailurePolicy标志,以便在@Before方法中出现错误时继续测试。但是,当一个测试出错时,有没有办法继续运行其余的测试呢。。比如说在测试类实例化过程中出现了一些异常

是否可以将此报告为错误并使生成失败

这是我的考试课

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文件