TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    TestNG

    TestNG @Test Annotation Attributes -2

    In this tutorial, we will look into more test annotation attributes. This post is a continuation of the earlier post here:    TestNG @Test Annotation Attributes

    @Test Annotation Attributes

    invocationCount

    The number of times this method should be invoked. The default value is 1.

    So both the below code snippets are equivalent.

    @Test(invocationCount=1) 
     public void testMethod1()
    { 
     System.out.println("count :" + i++); 
     } 
    
    
    @Test 
    public void testMethod2()
    { 
     System.out.println("count :" + i++); 
     }

     

    Let's see an example to run a test method for 3 times using invocationCount. Below is the code snippet.
    package com.testingdocs.testng.sample;
    
    import org.testng.annotations.Test;
    
    public class TestAnnotationExample
    {
     int i = 1;
     @Test(invocationCount=3) 
     public void testMethod()
     { 
     System.out.println("count :" + i++); 
     } 
     
    }

     

    Run output:

    count :1
    count :2
    count :3

    PASSED: testMethod
    PASSED: testMethod
    PASSED: testMethod

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

    The test method runs for 3 times as specified in the invocationCount attribute.

    invocationCount

     

    invocationTimeOut

    The maximum number of milliseconds that the total number of invocations on this test method should take.  This annotation will be ignored if the attribute invocationCount is not specified on this method.If it hasn’t returned after this time, it will be marked as a FAIL.

    If you are authoring test class in eclipse and if you make a typo in the attribute , just hover on the attribute  and eclipse would suggest quick fixes as shown below:

    QuickFixSuggestion

     

    threadPoolSize

    The size of the thread pool for this method.  The method will be invoked from multiple threads as specified by invocationCount. Note that this attribute is ignored if invocationCount is not specified.

    dataProvider

    The name of the dataProvider for this test method.

    dataProviderClass

    The class where to look for the data provider.  If not specified, the dataProvider will be looked on the class of the current test method or one of its superclasses. If this attribute is specified, the data provider method needs to be static on the specified class.

    For dataProvider example here: TestNG DataProvider Basic Example.

    alwaysRun

    If set to true, this test method will always be run even if it depends on a method that failed.  This attribute will be ignored if this test doesn’t depend on any method or group.

    expectedExceptions

    The list of exceptions that a test method is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure.

    expectedExceptionsMessageRegExp

    If expectedExceptions was specified, its message must match the regular expression specified in this attribute.

    singleThreaded

    If set to true, all the methods on this test class are guaranteed to run in the same thread, even if the tests are currently being run with a parallel option. This attribute can only be used at the class level and will be ignored if used at the method level.

     

    Related Posts

    Tests TestNG Suite testng.xml

    TestNG /

    Run tests from TestNG Suite testng.xml file

    Add TestNG library

    TestNG /

    Add the TestNG library to the project

    new TestNG class

    TestNG /

    Create TestNG test class in Eclipse IDE.

    TestNG Plugin IntelliJ

    TestNG /

    Enable TestNG in IntelliJ IDE

    Installing Eclipse from Update Site

    TestNG /

    Install TestNG latest version from the update site

    ‹ Enable and Disable Test in TestNG› Working with Assert in TestNG framework.

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com