Saturday, July 6, 2024

Define invocationCount to @Test

 Define invocationCount to @Test:

·  if we define @Test(invocationCount = 2): The test method will be executed 2 times.

·  if we define @Test(invocationCount = 3): The test method will be executed 3 times.

·  The invocationCount attribute can be used to invoke or run the test method multiple times.

 

package TestNgBasics1;

import org.testng.annotations.Test;

public class testInvocationCount {

           

//  define test method with invocationCount =2

            @Test(invocationCount = 2)

            public void login()

            {

                        System.out.println("This test method gets executed based on given invocation count=2");

            }

}

[RemoteTestNG] detected TestNG version 7.0.0

This test method gets executed given invocation count

This test method gets executed given invocation count

PASSED: login

PASSED: login

===============================================

    Default test

    Tests run: 2, Failures: 0, Skips: 0

===============================================

===============================================

Default suite

Total tests run: 2, Passes: 2, Failures: 0, Skips: 0

===============================================

(invocationCount = 0):

if we define invocationCount = 0, it will not execute test method

 

package TestNgBasics1;

import org.testng.annotations.Test;

public class testInvocationCount2 {

//         @Test(invocationCount = 2) //  this test method gets executed 2 times

            //                      3   -  executed 3 times

            @Test(invocationCount = 0) // it will not execute test method

            public void login()

            {

                        System.out.println("This test method will not be executed as  invocation count=0 ");

            }

}

 

o/p:

[RemoteTestNG] detected TestNG version 7.0.0

===============================================

    Default test

    Tests run: 0, Failures: 0, Skips: 0

===============================================

===============================================

Default suite

Total tests run: 0, Passes: 0, Failures: 0, Skips: 0

[TestNG] No tests found. Nothing was run

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...