TestNG

(Difference between revisions)
(TestNG support)
(Getting Started)
 
Line 41: Line 41:
=== Installation ===
=== Installation ===
-
* Open '''Tools''' -> '''Plugins'''
+
* Download and install [http://bits.netbeans.org/download/trunk/nightly/latest/ Development version] and you should be ready to go.
-
* Now depending on your preference and current IDE:
+
-
** IDE - [http://bits.netbeans.org/download/trunk/nightly/latest/ Development version]:
+
-
*** switch to '''Available Plugins''' tab
+
-
*** search for testng
+
-
*** select module(s) you want to install
+
-
*** hit '''Install''' button and follow the steps
+
-
** IDE - [http://netbeans.org/downloads/index.html Released version]:
+
-
*** '''either''' set up Development Update Center in '''Settings''' tab if you want to and follow steps in previous section '''Note:''' this may entice you to update IDE or some of its internals to the latest, greatest version - you've been warned :-)
+
-
*** '''or''' switch to '''Downloaded''' tab
+
-
*** use '''Add Plugins...''' button to add nbm files you downloaded
+
-
*** hit '''Install''' button and follow the steps
+
-
 
+
-
'''Figure 1:''' Installation from development update centre
+
-
[[image:plugins.png]]
+
=== Project setup ===
=== Project setup ===
Line 63: Line 49:
For already existing projects with some version of [http://testng.org 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 [http://testng.org TestNG] tests implemented in the Ant's build script or Maven's pom.
For already existing projects with some version of [http://testng.org 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 [http://testng.org TestNG] tests implemented in the Ant's build script or Maven's pom.
-
New projects and existing projects without any [http://testng.org 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 [[#Creating_Tests|provided wizards]]. This will add bundled TestNG library to the project and, in [http://ant.apache.org Ant] based projects, creates new build script, ''nbproject/testng-impl.xml'', which is used for running and debugging tests. If your project messes up by some accident, it is safe to use a copy of this file from different project.
+
New projects and existing projects without any [http://testng.org 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 [[#Creating_Tests|provided wizards]]. This will add bundled TestNG library to the project and, in [http://ant.apache.org Ant] based projects or set up dependency in pom.xml for [http://maven.apache.org/ Maven] based projects.
=== Creating Tests ===
=== Creating Tests ===

Current revision as of 19:40, 13 April 2012

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

Plugin Sources

Plugin Binaries

Development version:

Previous version:

  • available on the Plugin portal, for NetBeans 6.x

Getting Started

Installation

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 image:wizard1.png

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


caption
Navigation from testng.xml to particular test, test method, listener and other Java files as well as to other suite files imported from given file is supported through hyperlinks (CTRL+click)

Running and debugging of testng.xml files is supported from file's context menu caption

caption 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.

Image:resultsWindow_TestNG.png


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.

Image:resultsWindow_TestNG_2.png

Related stuff

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo