TestNG is a testing framework which, inspired by JUnit and NUnit, but introduces things like dependency testing, grouping concept to make testing more powerful and easier to do. It is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc...
The NG in TestNG stands for Next Generation. TestNG requires JDK7 or higher.
Reference: http://testng.org/doc/index.html
In this post, we will be discussing how to use TestNG to write a simple test:
Firstly, add the TestNG library in the pom.xml
Lets create a simple Java class that has a method that returns the String passed to it.
Create a test case like this:
Thats it, a simple TestNG test case is created.
The NG in TestNG stands for Next Generation. TestNG requires JDK7 or higher.
Reference: http://testng.org/doc/index.html
In this post, we will be discussing how to use TestNG to write a simple test:
Firstly, add the TestNG library in the pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.testng</groupId> | |
<artifactId>testng</artifactId> | |
<version>6.9.4</version> | |
<scope>test</scope> | |
</dependency> |
Lets create a simple Java class that has a method that returns the String passed to it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleString { | |
public String generateString(String str){ | |
return str; | |
} | |
} |
Create a test case like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.testng.Assert; | |
import org.testng.annotations.Test; | |
public class TestExampleString { | |
@Test() | |
public void testGenerateString(){ | |
ExampleString example = new ExampleString(); | |
String generateStr = example.generateString("Hello World"); | |
Assert.assertNotNull(generateStr); | |
Assert.assertEquals(generateStr,"Hello World"); | |
} | |
} |
Thats it, a simple TestNG test case is created.
No comments :
Post a Comment