【问题标题】:Is there a way to use a custom TestNG reporter with Junit tests?有没有办法在 Junit 测试中使用自定义 TestNG 报告器?
【发布时间】:2016-04-18 00:56:19
【问题描述】:

我有一个类似这样的自定义 TestNG 报告器:

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 测试。还有比这更简单的方法吗?

提前致谢。

【问题讨论】:

  • 欢迎来到 Stackoverflow。包括到目前为止您尝试过的代码 sn-ps。
  • 您的记者代码在哪里?你实现了什么 IReporter 或 Listener?
  • 这里无法添加reporter代码,但是我已经实现了IReporter
  • 我已经添加了自定义记者。

标签: java unit-testing junit automated-tests testng


【解决方案1】:

我使用以下方法解决了在 TestNG 下运行 Junit 测试的问题:http://www.tutorialspoint.com/testng/testng_run_junit_tests.htm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-19
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多