Enabled Attribute or Property in
@Test:
· @Test(enabled = false): The test method testA will not run because it is disabled.
· @Test(enabled = true): The test method testB will run because it is explicitly enabled.
· @Test: The test method testC will run because the default value for enabled is true.
package TestNgBasics1;
import org.testng.annotations.Test;
public class TestMethodWithEnable {
// Define test method
with enabled = false
@Test(enabled = false)
// If we write Test
method with enabled = false, it will not execute that test method
public void testA() {
System.out.println("test A - is not executed if the test method is
defined with enabled = false");
}
// Define test method
with enabled = true
@Test(enabled = true)
public void testB() {
System.out.println("test B - is
executed if the test method is defined with enabled = true");
}
// Define test method
without specifying enabled attribute, default enabled = true
@Test // If we don't
define enabled, default enabled = true
public void testC() {
System.out.println("test C - is executed if the test method is
defined with enabled = true (default)");
}
}
o/p:
[RemoteTestNG] detected
TestNG version 7.0.0
test B - is executed
if test method is defined with enabled = true
test C methods - is executed
if test method is defined with enabled = true
PASSED: testB
PASSED: testC
===============================================
Default test
Tests run: 2, Failures:
0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 2, Passes: 2, Failures: 0, Skips: 0
===============================================
No comments:
Post a Comment