- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to turn off TestNG's default reporters programmatically?
TestNG allows to run the test suites from IntelliJ IDE as well as from the command line. When user runs the testNG.xml either from an IDE or the command line, TestNG generates a default report. It saves all the reports and respective HTML files in the Project->test-output folder. If this folder does not exist, then TestNG creates one.
To disable the default reports programmatically, TestNG should be run through the command line (cmd).
Following are the prerequisites to run the test suites from the command line −
testNG.xml file should be created to define the test suites and testing classes to execute.
All the dependent jars should be available inside a project folder. It includes testing.jar, jcommander.jar and any other jars that are used in the test cases.
The Path of bin or out folder where .class files are stored after compilation.
Approach/Algorithm to solve this problem −
Step 1 − Create different testing classes having different @Test methods and one @BeforeSuite method.
Step 2 − Compile the class. It will create an out folder in IntelliJ and bin folder in Eclipse.
Step 3 − Place all the jar files in the lib folder.
Step 4 − Now create the testNG.xml as given below.
Step 5 − Open the cmd.
Step 6 − Navigate to the project path using cd <project_path>
Step 7 − Run the following command:
java -cp <path of lib;> <path of out or bin folder> org.testng.TestNG <path of testng>/testng.xml
Example
The following code shows how to disable the default report generation at runtime −
src/ NewTestngClass.java
import org.testng.TestNG; import org.testng.annotations.*; public class NewTestngClass { // test case 1 @Test() public void testCase1() throws InterruptedException { System.out.println("in test case 1 of NewTestngClass"); } // test case 2 @Test() public void testCase2() throws InterruptedException { System.out.println("in test case 2 of NewTestngClass"); } @BeforeSuite public void name() { TestNG myTestNG = new TestNG(); myTestNG.setUseDefaultListeners(false); System.out.println("Default reports are disabled"); } }
src/testng.xml
This is a configuration file that is used to organize and run the TestNG test cases. It is very handy when limited tests are needed to execute rather than the full suite.
<?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name = "Suite1"> <test name = "test1"> <classes> <class name = " NewTestngClass"/> </classes> </test> </suite>
Command to run −
java -cp .\lib\*;.\out\production\TestNGProject org.testng.TestNG src\testng.xml
Output
Default reports are disabled in test case 1 of NewTestngClass in test case 2 of NewTestngClass =============================================== Suite1 Total tests run: 2, Passes: 2, Failures: 0, Skips: 0 ===============================================
- Related Articles
- How to programmatically turn off and turn on WiFi in Kotlin?
- How to turn Android device screen on and off programmatically?
- How to turn Android device screen on and off programmatically using Kotlin?
- How to turn off transparency in Matplotlib's 3D Scatter plot?
- How to Turn Off Form Autocompletion in HTML?
- How to turn on Flash light programmatically in android?
- How to programmatically turn on Wifi on Android device?
- How to turn on flashlight programmatically in Android using Kotlin?
- How to turn off YouTube comments in YouTube Mobile app?
- How to turn off spell checking (grammar correction) for HTML form elements?
- How to turn off error bars in Seaborn Bar Plot using Matplotlib?
- How to turn off the upper/right axis tick marks in Matplotlib?
- How to turn off the ticks and marks of a matlibplot axes?
- How to turn on and off the Incognito Mode on YouTube App
- Golang program to turn off the k’th bit in a number.
