Wednesday 11 March 2020

TestNG: Ignore or disable test cases from execution

‘@Test(enabled = false)’ statement is used to disable the test cases.

Example
@Test(enabled = false)
public void test1() {
         System.out.println("test1 in execution");
}

IgnoreTests.java
package com.sample.app.tests;

import org.testng.annotations.Test;

public class IgnoreTests {

 @Test(enabled = false)
 public void test1() {
  System.out.println("test1 in execution");
 }

 @Test
 public void test2() {
  System.out.println("test2 in execution");
 }

}

Run IgnoreTests.java, you will see below messages in console.
[RemoteTestNG] detected TestNG version 7.0.0
test2 in execution
PASSED: test2

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================

As you see the console messages, you can confirm that test1 is not executed.

Previous                                                    Next                                                    Home

No comments:

Post a Comment