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

Introduction

@Test is the basic annotation of the TestNG framework. We can mark a class or a test with this annotation as part of TestNG tests. If we apply the @Test at the class level all the public methods inside the class are marked as test methods for the TestNG tests. Test annotation has a lot of attributes that we can use along with the annotation as shown in the below picture.

@Test

We will discuss some things about Test annotation in this post.

Import Test annotation in a test class.

Hover on the @Test annotation and import as shown.

 

 

description

The description of the method. The string used will appear in the HTML report and also on standard output if verbose >= 2.

Code snippet:

package com.testingdocs.testng.sample;

import org.testng.annotations.Test;

public class TestAnnotationExample
{
 @Test(description="SampleDescription")
 public void sampleTestName()
 {
 System.out.println("Sample Test");
 }

}

 

Run output:

PASSED: sampleTestName
SampleDescription

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

groups

The list of groups the class/method belongs to.

@Test(groups="group1")
 public void test1()
 { 
 System.out.println("Group1 test");
 }

 

Consider reading : TestNG Test Groups

enabled

Specifies whether methods on the class/method are enabled or disabled.

dependsOnGroups

The list of groups the method depends on.  Every method member of one of these groups is guaranteed to have been invoked before this method.  Furthermore, if any of these methods was not a SUCCESS, this test method will not be run and will be flagged as a SKIP.

dependsOnMethods

The list of methods the method depends on.  There is no guarantee on the order on which the methods depended upon will be run, but you are guaranteed that all these methods will be run before the test method that contains this annotation is run.  Furthermore, if any of these methods was not a SUCCESS, this test method will not be
run and will be flagged as a SKIP.

If some of these methods have been overloaded, all the overloaded versions will be run.

timeOut

The maximum number of milliseconds the test should take. If it hasn’t returned after this time, it will be marked as a FAIL.

 

TestNG Tutorials on this website can be found at:

https://www.testingdocs.com/testng-framework-tutorial/

For more details on the TestNG Framework, visit the official website of TestNG at:

https://testng.org

Related Posts

TestNG /

Run tests from TestNG Suite testng.xml file

TestNG /

Add the TestNG library to the project

TestNG /

Create TestNG test class in Eclipse IDE.

TestNG /

Enable TestNG in IntelliJ IDE

TestNG /

Install TestNG latest version from the update site

‹ Test Driven Development Approach› Exception Test TestNG Example

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com