Java - Turn off TestNG's default reporters programmatically

Varun Mulloli

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();
}

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);
    }
}

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 programmatically?

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

Varun Mulloli

Found the answer.

myTestNG.setUseDefaultListeners(false);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Turn off spellcheck in OneNote 2010

분류에서Dev

Turn off the link hover statusbar in Google Chrome

분류에서Dev

Redirect APPCRASH Dumps (Or turn them off)

분류에서Dev

Windows 7 does not turn off monitor displays

분류에서Dev

How to turn off Wireless power management permanently

분류에서Dev

Extension to turn off certain page element?

분류에서Dev

Turn off history for Durandal child router

분류에서Dev

Windows 10: Laptop display refuses to turn off

분류에서Dev

Android 5 turn off Interruptions filtration

분류에서Dev

Chrome - Turn off bell for find in page no results?

분류에서Dev

How to turn off screen (headless installation)

분류에서Dev

Turn off screen with password protection but no sleep

분류에서Dev

Turn off auth in ubuntu 19.10 in all components

분류에서Dev

Turn off smooth scrolling in GTK3

분류에서Dev

Monit to turn off machine when program is done

분류에서Dev

"[TTM] Buffer eviction failed" on Ubuntu turn off

분류에서Dev

List of all default application programmatically

분류에서Dev

Getting a reference to Java's default http(s) URLStreamHandler

분류에서Dev

Turn screen off when inactive for time period in RHEL and Debian

분류에서Dev

How do I turn off all the password prompts?

분류에서Dev

How to turn off one of SATA HDDs installed in the computer to save power?

분류에서Dev

Is it possible to turn off case insensitivity using pattern only?

분류에서Dev

How to turn off single user mode on a remote machine?

분류에서Dev

Disable "Turn off hard disk after" in windows 7

분류에서Dev

DMX Arduino - Turn OFF lamp on Martin Exterior 600 fixture

분류에서Dev

Is it possible to turn off antialiasing in SceneKit to make pixel art images sharp?

분류에서Dev

Turn off Snap-Assist-like feature in Windows 10 (for notebooks)

분류에서Dev

turn off noise on kinesis keyboard caps-lock

분류에서Dev

How to turn off write protection in win 7 using diskpart?

Related 관련 기사

  1. 1

    Turn off spellcheck in OneNote 2010

  2. 2

    Turn off the link hover statusbar in Google Chrome

  3. 3

    Redirect APPCRASH Dumps (Or turn them off)

  4. 4

    Windows 7 does not turn off monitor displays

  5. 5

    How to turn off Wireless power management permanently

  6. 6

    Extension to turn off certain page element?

  7. 7

    Turn off history for Durandal child router

  8. 8

    Windows 10: Laptop display refuses to turn off

  9. 9

    Android 5 turn off Interruptions filtration

  10. 10

    Chrome - Turn off bell for find in page no results?

  11. 11

    How to turn off screen (headless installation)

  12. 12

    Turn off screen with password protection but no sleep

  13. 13

    Turn off auth in ubuntu 19.10 in all components

  14. 14

    Turn off smooth scrolling in GTK3

  15. 15

    Monit to turn off machine when program is done

  16. 16

    "[TTM] Buffer eviction failed" on Ubuntu turn off

  17. 17

    List of all default application programmatically

  18. 18

    Getting a reference to Java's default http(s) URLStreamHandler

  19. 19

    Turn screen off when inactive for time period in RHEL and Debian

  20. 20

    How do I turn off all the password prompts?

  21. 21

    How to turn off one of SATA HDDs installed in the computer to save power?

  22. 22

    Is it possible to turn off case insensitivity using pattern only?

  23. 23

    How to turn off single user mode on a remote machine?

  24. 24

    Disable "Turn off hard disk after" in windows 7

  25. 25

    DMX Arduino - Turn OFF lamp on Martin Exterior 600 fixture

  26. 26

    Is it possible to turn off antialiasing in SceneKit to make pixel art images sharp?

  27. 27

    Turn off Snap-Assist-like feature in Windows 10 (for notebooks)

  28. 28

    turn off noise on kinesis keyboard caps-lock

  29. 29

    How to turn off write protection in win 7 using diskpart?

뜨겁다태그

보관