Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 有没有办法在Junit测试中使用自定义TestNG reporter?_Java_Unit Testing_Junit_Automated Tests_Testng - Fatal编程技术网

Java 有没有办法在Junit测试中使用自定义TestNG reporter?

Java 有没有办法在Junit测试中使用自定义TestNG reporter?,java,unit-testing,junit,automated-tests,testng,Java,Unit Testing,Junit,Automated Tests,Testng,我有一个定制的TestNG reporter,如下所示: import java.util.List; import java.util.Map; import org.testng.IReporter; import org.testng.ISuite; import org.testng.ISuiteResult; import org.testng.ITestContext; import org.testng.xml.XmlSuite; public class CustomRepo

我有一个定制的TestNG reporter,如下所示:

import java.util.List;
import java.util.Map;

import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestContext;
import org.testng.xml.XmlSuite;

public class CustomReporter implements IReporter{
    @Override
    public void generateReport(List xmlSuites, List suites,
        String outputDirectory) {
        //Iterating over each suite included in the test
        for (ISuite suite : suites) {
            //Following code gets the suite name
            String suiteName = suite.getName();
        //Getting the results for the said suite
        Map suiteResults = suite.getResults();
        for (ISuiteResult sr : suiteResults.values()) {
            ITestContext tc = sr.getTestContext();
            System.out.println("Passed tests for suite '" + suiteName +
                 "' is:" + tc.getPassedTests().getAllResults().size());
            System.out.println("Failed tests for suite '" + suiteName +
                 "' is:" + 
                 tc.getFailedTests().getAllResults().size());
            System.out.println("Skipped tests for suite '" + suiteName +
                 "' is:" + 
                 tc.getSkippedTests().getAllResults().size());
          }
        }
    }
}
我想在JUnit测试中使用它。有没有比这更简单的方法


提前感谢。

我使用此方法解决了在TestNG下运行Junit测试的问题:

我使用此方法解决了在TestNG下运行Junit测试的问题:

欢迎使用Stackoverflow。包括您迄今为止尝试过的代码片段。您的reporter代码在哪里?您实现了什么IReporter或Listener?我无法在此处添加报告程序代码,但我已经实现了IReporter。我已经添加了自定义报告程序。欢迎使用Stackoverflow。包括您迄今为止尝试过的代码片段。您的reporter代码在哪里?您实现了什么IReporter或Listener?我无法在此处添加报告程序代码,但我已经实现了IReporter。我已经添加了自定义报告程序。