testng

What TestNG?

Tag(s):

TestNG is a java testing framework. It was created by Cédric Beust out of frustration over JUnit's deficiencies. It was designed to cover all categories of tests such as unit, functional, integration, etc.

The idea is very simple. It is breakdown into the following steps:

Ant build using TestNG-XSLT

Tag(s):

Ant build using TestNG-XSLT

<!-- 
  Example for TestNG-XSLT
    Run this target only after TestNG had generated the xml resutl file(i.e. testng_output/testng-results.xml).

Ant build file for TestNG

Tag(s):

Sample Ant build file to run TestNG

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

Testing private methods

Tag(s):

Sometimes you need to test the private method of a class. I use reflection to access the private method. Here are the codes:

Run specific groups of tests

Tag(s):

One of the nice features of TestNG is that it allows you to run specific groups of tests among all the tests that you have written. In my case, this feature is handy when I want to run read only tests on the production environment. The idea is to associate each test method to a group. When you want to run each group of tests separately, you only invoke your desired groups through the configuration file of TestNG. The following shows you how to do it.

Execution order of TestNG's annotations

Tag(s):

Codes below show the execution order of commonly used annotations of TestNG.

First TestNG test

Tag(s):

Write TestNG test

Writing tests using TestNG is easy. There are only 2 steps:

Test an exception with Testng

Tag(s):

package net.xngo.tutorial.java.testng;
 
import static org.testng.Assert.assertTrue;

Using hamcrest in TestNG

package net.xngo.tutorial.java.testng;
 
import static org.hamcrest.MatcherAssert.assertThat;

Unit test standard output, System.out.println

Tag(s):

package net.xngo.tutorial.java.testng;
 
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

Pages

Subscribe to RSS - testng