TestNG is a testing framework inspired from JUnit and NUnit but with new functionality to make it more powerful and easier to use. Features include:
TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc...
The sections below illustrate using TestNG for the examples from Using Testing Frameworks with Groovy.
Here is how you might use TestNG to integration test the Item Storer Example:
// require(groupId:'org.testng', artifactId:'testng', version='5.6')
import org.testng.annotations.*
import org.testng.TestNG
import org.testng.TestListenerAdapter
class StorerIntegrationTest {
private storer
@BeforeClass
def setUp() {
storer = new Storer()
}
private checkPersistAndReverse(value, reverseValue) {
storer.put(value)
assert value == storer.get()
assert reverseValue == storer.getReverse()
}
@Test
void shouldPersistAndReverseStrings() {
checkPersistAndReverse 'hello', 'olleh'
}
@Test
void shouldPersistAndReverseNumbers() {
checkPersistAndReverse 123.456, -123.456
}
@Test
void shouldPersistAndReverseLists() {
checkPersistAndReverse([1, 3, 5], [5, 3, 1])
}
}
def testng = new TestNG()
testng.setTestClasses(StorerIntegrationTest)
testng.addListener(new TestListenerAdapter())
testng.run()
|
You might also like to consider the special Groovy integration from the Test'N'Groove project which provides command-line runners and ant tasks for using TestNG with Groovy.