Running Tests on a Platform Application

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

The following article describes some of the ways you can run tests (whether unit or functional) on a NetBeans Platform application.

What is a unit test versus a functional test?

Unit test is a test on a method not on the overall functionality of a tool or application. Example of unit test if testing of a method than should return always positive integer. Functional test is testing the overall encryption algorithm that uses that method.

From the NetBeans IDE

  • You can run a single test from the IDE by right-clicking the test’s node within the project explorer and choosing 'Test' from the context menu. If you have the test source file (or the class which corresponds to the test case) open in the editor, you can run it by pressing Ctrl+F6 or its equivalent for your operating system.

  • You can run all tests within a single module by right-clicking the module in the project explorer and choosing 'Test' from the context menu. The default shortcut for this on Windows and most Unix systems is Alt+F6.

  • You can run all tests for the entire application by right-clicking the suite node in the project explorer and choosing 'Test All' from the context menu.

From the Command Line Using Ant

  • You can run a single unit test by by typing ant test-unit -Dtest.class=com.tomwheeler.example.MyTestClass in the module’s directory (where com.tomwheeler.example.MyTestClass is the name of the unit test class you want to execute). You can add additional JVM arguments by specifying them in the test.run.args system property, but be sure to quote them as appropriate for your operating system.

  • You can run a single functional (GUI) test from the command line by typing ant test-qa-functional -Dtest.class=com.tomwheeler.example.MyTestClass in the module’s directory. As with unit tests, you can specify additional JVM arguments using the test.run.args system property.

  • You can run all unit tests for a module by running the ant test command from the module’s directory.

  • You can run all unit tests for the entire suite by running the ant test command from the suite directory.

Unit Test Code Coverage

The NetBeans Platform has inherently supported unit test code coverage (using Cobertura) since version 6.7. To generate a report which measures unit test code coverage for a single module, type ant display-coverage-report from that module’s directory. Likewise, you can generate a report which measures unit test code coverage for all unit tests in the entire suite by typing ant display-coverage-report from the suite’s directory. See also Code Coverage.

Debugging Unit Tests From the Command Line

Debugging tests from using the NetBeans IDE should be pretty straightforward, but if you want to debug a unit test from the command line (i.e. because you want to attach the debugger in a different IDE), then you simply need to run the test from the command line as described above but specify -Dtest.run.args="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005". The test will compile and start to run, but will pause execution until you attach the debugger on port 5005.