TestNG
TestNG is a new generation testing framework developed due to stagnation of JUnit at version 3.8.x.
TestNG support
Adds support for creating, running, debugging and displaying results for TestNG tests in Ant and Maven based projects in NetBeans 7.2 and/or later.
This is work in progress so don't hesistate to file any issues to Bugzilla (java/testng)
Instructions for the Maven part of the plugin are yet TBD
Author: Lukas Jungmann (jungi (at) netbeans (dot) org)
Last Update: April 13, 2012
Contents
|
Issues
- Opened issues
- File new issue
Plugin Sources
- TestNG library (for NB platform based applications): hg.netbeans.org/main/file/tip/libs.testng/
- Generic support: hg.netbeans.org/main/file/tip/testng/
- Ant support: hg.netbeans.org/main/file/tip/testng.ant/
- Maven support: hg.netbeans.org/main/file/tip/testng.maven/
Plugin Binaries
Development version:
- latest daily build
Previous version:
- available on the Plugin portal, for NetBeans 6.x
Getting Started
Installation
- Download and install Development version and you should be ready to go.
Project setup
IMPORTANT: Compile on Save feature has not yet been implemented for TestNG tests, so as the very first step after creating a project, disable this feature in Project Properties -> Compiling -> Compile on Save to avoid unexpected behaviour, please. This is known issue.
For already existing projects with some version of TestNG on its classpath no setup is needed. In this case the plugin just assumes that project has either already been setup by this plugin or you have already some targets running TestNG tests implemented in the Ant's build script or Maven's pom.
New projects and existing projects without any TestNG library on the classpath will be setup by this plugin as soon as you create at least one test or test suite using one of provided wizards. This will add bundled TestNG library to the project and, in Ant based projects or set up dependency in pom.xml for Maven based projects.
Creating Tests
Plugin comes with two wizards - one to help you to create a simple test and the second to create xml suite
Figure 2: New File wizard with TestNG file templates
New TestNG Test Case wizard will help you to create regular valid TestNG java test file with sample content, while New TestNG Test Suite wizard will help you to create TestNG suite descriptor file in XML format, again with some sample content. You can customize both templates through Tools -> Templates.
Running Tests
Test project (ALT+F6), Run File (Shift+F6) and Test File (CTRL+F6) actions defined in the IDE do work for TestNG tests in the same way as they do for JUnit tests.
The only difference here is Run Focused Test action. This action has its equivalent in TestNG -> Run Test Method action.
Debugging Tests
To debug your TestNG tests, you can't currently use IDE wide actions you're used to from JUnit support by default. These actions are implemented as TestNG -> Debug Test Class and TestNG -> Debug actions which work in the same way as Debug Test File and Debug Focused Test do.
We're working hard on merging TestNG -> Debug Test Class and Debug Test File (CTRL+Shift+F6) actions together and until this is resolved, we provided workaround for this. All you need to do in order to get the shortcut working is to change the build.xml file of your project to start with:
<project name="JavaApplication1" default="default" basedir="."> <description>Builds, tests, and runs the project JavaApplication1.</description> <import file="nbproject/testng-impl.xml"/> <import file="nbproject/build-impl.xml"/> ...
Running/Debugging Tests in NetBeans 6.5
Following table gives an overview about supported ways to run/debug tests:
Action | Ant projects - disabled compile on save | Ant projects - enabled compile on save | Maven projects |
---|---|---|---|
Run all tests in a project | Test (Alt+F6) | Test (Alt+F6) | Test (Alt+F6) |
Run test | Run File (Shift+F6) | TestNG -> Run Test Class | Run File (Shift+F6) |
Run test method | TestNG -> Run Test Method | TestNG -> Run Test Method | TestNG -> Run Test Method |
Re-run failed test(s) | TestNG -> Re-run Failed Tests | TestNG -> Re-run Failed Tests | TestNG -> Re-run Failed Tests |
Debug test | TestNG -> Debug Test Class | TestNG -> Debug Test Class | TestNG -> Debug Test Class |
Debug test method | TestNG -> Debug Test Method | TestNG -> Debug Test Method | TestNG -> Debug Test Method |
Note: TestNG here refers to TestNG action group in editor's context menu
testng.xml Support
Running and debugging of testng.xml files is supported from file's context menu
Code completion is supported based on testng-1.0.dtd
TestNG Results Window
Results window provides the same set of features which are you used to from JUnit's test results window - you can Go To Source, View Difference, Run one particular test method again or immediatelly Debug it. You can also filter results according to its state and Jump from one failure to the next or previous one.
If your project uses TestNG v. 6.3.1 or newer you will see test result to be reported incrementally (we submitted patch to TestNG allowing us to implement this feature and it has been accepted in v. 6.3.1). For older versions of TestNG, test results remain displayed based on the testng-results.xml file which is produced by TestNG after all tests are run.
Related stuff
- There are plans to improve the TestNG support in year 2012
- Mixed Mode for TestNG
- UnitTests
- testng.org/