TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • TestNG
  • Tools
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

TestNG

Create TestNG test class in Eclipse IDE.

Overview

We can easily create a TestNG test class template with annotations using the TestNG plugin feature.

Create a TestNG class

Option1

Click  File >> New >> Other…

Search for TestNG and choose TestNG class.

new TestNG class

Option2

Steps to create a TestNG class in Eclipse.

Launch Eclipse IDE.

Choose the test package to create the class.

Right-click on the Package Explorer.

Choose TestNG >> Create TestNG class.

 

Create TestNG class

 

In the next screen, we can choose the TestNG test class name, TestNG annotations.

Click on the Finish button.

Sample TestNG class

More Information on the TestNG annotations:

https://www.testingdocs.com/testng-annotations/

TestNG test class template

We can add the test logic to the TestNG test methods and the various annotated methods.

package airplane;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;

public class SampleTestNGClass {
 @Test
 public void f() {
 }
 @BeforeMethod
 public void beforeMethod() {
 }

 @AfterMethod
 public void afterMethod() {
 }

 @BeforeClass
 public void beforeClass() {
 }

 @AfterClass
 public void afterClass() {
 }

 @BeforeTest
 public void beforeTest() {
 }

 @AfterTest
 public void afterTest() {
 }

 @BeforeSuite
 public void beforeSuite() {
 }

 @AfterSuite
 public void afterSuite() {
 }

}

 

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

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

TestNG Plugin IntelliJ

TestNG /

Enable TestNG in IntelliJ IDE

Installing Eclipse from Update Site

TestNG /

Install TestNG latest version from the update site

Before and After TestNG Annotations

TestNG /

TestNG Before and After Annotations

‹ Enable TestNG in IntelliJ IDE› Add the TestNG library to the project

Recent Posts

  • Antivirus Products for Windows 11 PC
  • Install CodeBlocks IDE on Windows 11
  • Location Privacy Settings on Windows
  • Windows 11 Virus & Threat Protection
  • Download & Install Python on Windows 11
  • Cumulative Update for Windows 11 Version
  • Test execution speed in Selenium IDE
  • Check Windows 11 Free Upgrade
  • Download IntelliJ IDE on Windows 11
  • New MySQL Connection in Workbench

Back to Top

Automation Tutorials

  • JBehave Tutorial
  • Selenium Tutorial
  • TestNG Tutorial
  • JUnit Tutorial

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version