TestNG Tutorials 65 : Dry Run Feature in TestNG

As a part of TestNG Tutorials, in this post we will see a new feature provided by TestNG called Dry run of test methods.

You may heard of the term “Dry Run” in Cucumber. If you want to check that every step in a feature file has its corresponding step definitions, we can run feature file with dryRun cucumber option.

Similar kind of feature is provided by TestNG now. If you want to see a list of the test methods that would be invoked on run without running them actually, you can use dry run feature. Remember it will give only @Test annotated methods not configuration methods like @BeforeXXXX and @AfterXXXX.

We will see an example so that it will be more clear to you:-

Testclass1.java:-

package TestMethods1;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestClass1 {
	
	
	@BeforeTest
	public void BeforeTestMethod()
	{
		System.out.println("BeforeTest");
	}
	
	
	@Test 
	public void TestClass1Method1()
	{
		System.out.println("TestClass1 Method1");
		
		
	}
	
	
	@Test
	public void TestClass1Method2()
	{
		System.out.println("TestClass1 Method2");
		
		
	}

}

Testclass2.java:-

package TestMethods1;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestClass2 {
	
	@BeforeTest
	public void BeforeTestMethod1()
	{
		System.out.println("BeforeTest1");
	}
	
	@Test
	public void TestClass2Method1()
	{
		System.out.println("TestClass2 Method1");
		
		
	}
	
	
	@Test
	public void TestClass2Method2()
	{
		System.out.println("Test Class2 Method2");
		
		
	}

}

Testng.xml:-




  
    
      
      
    
   
 

To run in dry run mode, we need to pass a JVM argument as -Dtestng.mode.dryrun=true

Go to Run configuration and select your project and pass argument as shown below:-

Now run and see output. You will see methods are called but was not run.

Let’s disable a test method and rerun:-

package TestMethods1;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

public class TestClass1 extends TestBase{
	
	
	@BeforeTest
	public void BeforeTestMethod()
	{
		System.out.println("BeforeTest");
	}
	
	
	@Test @Ignore
	public void TestClass1Method1()
	{
		System.out.println("TestClass1 Method1");
		System.out.println(name);
		
	}
	
	
	@Test
	public void TestClass1Method2()
	{
		System.out.println("TestClass1 Method2");
		System.out.println(name);
		
	}

}

You can play around this feature with include and exclude groups. This feature is helpful to know if all your intended test methods will run or not.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.



Leave a Reply

Your email address will not be published. Required fields are marked *