0% found this document useful (0 votes)
9 views4 pages

TestNG POC

Uploaded by

Venkata Ramana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

TestNG POC

Uploaded by

Venkata Ramana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

TestNG POC - Proof of Concept

Key Features and Examples

1. Introduction to TestNG:

TestNG is a testing framework inspired by JUnit and NUnit but introduces new functionalities.

Key Features:

- Annotations for test methods.

- Support for data-driven testing.

- Parallel test execution.

2. TestNG Annotations:

@Test - Marks a method as a test method.

@BeforeMethod - Executes before each test method.

@AfterMethod - Executes after each test method.

Code Example:

import org.testng.annotations.Test;

public class TestNGExample {

@Test

public void testMethod() {

System.out.println("TestNG Test Method");

3. TestNG XML Configuration:


TestNG XML allows for flexible test configurations.

Example:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Test Suite">

<test name="Test">

<classes>

<class name="com.example.TestNGExample" />

</classes>

</test>

</suite>

4. Parameterized Tests:

TestNG supports parameterization via XML.

Example:

@Test

@Parameters({"param"})

public void parameterizedTest(String param) {

System.out.println("Parameter: " + param);

5. Data-Driven Testing with @DataProvider:

@DataProvider provides data for test methods.

Example:
@DataProvider(name = "data")

public Object[][] dataProvider() {

return new Object[][] {{"data1"}, {"data2"}};

@Test(dataProvider = "data")

public void dataDrivenTest(String data) {

System.out.println("Test Data: " + data);

6. Grouping Tests:

TestNG supports grouping tests.

Example:

@Test(groups = {"group1"})

public void groupTest() {

System.out.println("Group Test");

7. Parallel Testing:

TestNG allows running tests in parallel.

XML Configuration:

<suite name="Suite" parallel="methods" thread-count="2">

<test name="Test">

<classes>

<class name="com.example.TestNGExample" />


</classes>

</test>

</suite>

8. TestNG Reports:

TestNG generates HTML and XML reports for test results.

Command:

Run `testng your-testng.xml` to execute tests and generate reports.

9. Integration with Build Tools:

TestNG integrates with Maven and Gradle.

Maven POM Dependency:

<dependency>

<groupId>org.testng</groupId>

<artifactId>testng</artifactId>

<version>7.9.0</version>

<scope>test</scope>

</dependency>

You might also like