Chapter 10. Using TestNG project

10.1. What is TestNG?

TestNG ("Testing, the Next Generation") is a Java unit testing framework that aims to overcome many limitations of JUnit. TestNG introduces some new functionalities that make it more powerful and easier to use, such as:

  • JDK 5 Annotations (JDK 1.4 is also supported with JavaDoc annotations)

  • Flexible test configuration

  • Support for data-driven testing (with @DataProvider)

  • Support for parameters

  • Allows distribution of tests on slave machines

  • Powerful execution model (no more TestSuite)

  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...)

  • Embeds BeanShell for further flexibility

  • Default JDK functions for runtime and logging (no dependencies)

  • Dependent methods for application server testing

More information can be found on home page: www.testng.org

10.2. Other relevant resources on the topic

Next-Generation Testing with TestNG (An Interview with Cedric Beust)

TestNG: The next generation of unit testing

Test Categorization Techniques with TestNG

TestNG makes Java unit testing a breeze

In pursuit of code quality: JUnit 4 vs. TestNG

10.3. How to use the generated Seam-test project to run Seam tests?

  • Create a new Seam Web Project with EAR deployment using the New Seam Project wizard.

  • After a project is created you will have the generated Seam-test project that is setup to run TestNG directly against the proper libraries and server runtime libraries.

Seam-test Project

Figure 10.1. Seam-test Project


  • Add Seam Action to your project via File > New > Seam Action.

Seam Action Creation

Figure 10.2. Seam Action Creation


  • Fill out the wizard fields. New Seam Action wizard will create resources and place them in the appropriate folders dependent on EAR project structure.

New Seam Action Wizard

Figure 10.3. New Seam Action Wizard


  • When Action is created you will see actionPage.xhtml in Package Explorer view. ActionBean.java will be automatically opened in Java Editor.

Created Action

Figure 10.4. Created Action


  • Select ActionLocalTest.xml in Seam-test project and run the test with right click Run As > TestNG Suite.

Running TestNG

Figure 10.5. Running TestNG


The test process will start and its output will be written in Console View.

Test is Finished

Figure 10.6. Test is Finished


  • After running TestNG you will have the test results in test-output folder in Seam-test project (press F5 to refresh the Package Explorer view). Open index.html file with Web Browser or simply use the TestNG view.

The below view shows a successful run of the test.

Viewing the Test Results

Figure 10.7. Viewing the Test Results


You can see the test results in Web Browser.

Test Results in Browser

Figure 10.8. Test Results in Browser


After clicking on ActionLocal Tests link you will see the Results for ActionLocal Tests.

Test Information

Figure 10.9. Test Information


Select a result on the left-hand pane and its details will be displayed on the right-hand one.

ActionLocal Test Details

Figure 10.10. ActionLocal Test Details