Java - 以编程方式关闭TestNG的默认记者 [英] Java - Turn off TestNG's default reporters programatically

查看:192
本文介绍了Java - 以编程方式关闭TestNG的默认记者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我需要从我的main方法执行我的TestNG @Test注释方法,并使用ReportNG生成报告。

I have an application where I need to execute my TestNG @Test annotated methods from my main method, and use ReportNG to generate reports.

我的主要方法看起来像这个:

My main method looks like this:

public static void main(String args[])
{
    TestNG myTestNG = new TestNG();
    XmlSuite mySuite = new XmlSuite();
    mySuite.setName("Sample Suite");
    mySuite.addListener("org.uncommons.reportng.HTMLReporter");
    mySuite.addListener("org.uncommons.reportng.JUnitXMLReporter");
    XmlTest myTest = new XmlTest(mySuite);
    myTest.setName("Sample Test");
    List<XmlClass> myClasses = new ArrayList<XmlClass>();
    myClasses.add(new XmlClass("com.varunmulloli.testng.SampleTest"));
    myTest.setXmlClasses(myClasses);
    List<XmlTest> myTests = new ArrayList<XmlTest>();
    myTests.add(myTest);
    mySuite.setTests(myTests);
    List<XmlSuite> mySuites = new ArrayList<XmlSuite>();
    mySuites.add(mySuite);
    myTestNG.setXmlSuites(mySuites);
    myTestNG.run();
}

我的 SampleTest class看起来像这样:

And my SampleTest class looks like this:

public class SampleTest 
{
    @Test
    public void testSample() 
    {
        String str = "TestNG is working fine";
        assertEquals("TestNG is working fine", str);
    }
}

代码运行正常,但在测试输出中文件夹,我得到了默认的TestNG记者生成的报告以及ReportNG报告。如何以编程方式禁用默认报告者?

The code runs fine, but in the test-output folder, I get the reports generated by the default TestNG reporter as well along with the ReportNG reports. How do I disable the default reporters programatically?

关闭测试输出在TestNG中 - 这个问题与我的相似,但它没有讨论以编程方式禁用它。

Turning off test-output in TestNG - This question is similar to mine, but it does not discuss about disabling it programatically.

推荐答案

发现答案。

myTestNG.setUseDefaultListeners(false);

这篇关于Java - 以编程方式关闭TestNG的默认记者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆