JUnit is a simple, open source framework for writing and running automated tests. It is an instance of the xUnit architecture for unit testing frameworks.
This tutorial shows you how to use the NetBeans IDE for JUnit development.
The NetBeans Integrated Development Environment (IDE) is a free, open-source Integrated Development Environment for software developers. The NetBeans IDE provides developers with all the tools they need to create professional cross-platform desktop, enterprise, web, and mobile applications. In this tutorial, you learn how to convert a JUnit project into a Netbeans project to develop, build, and test JUnit within the Netbeans IDE.
For more information on how to work with the NetBeans IDE, see the Support and Docs page.
Before you begin, you need to install the following software on your computer: NetBeans IDE 6.0.
Since NetBeans 6.0 is under development now, use NetBeans IDE 6.0 Preview (M10) available from NetBeans IDE 6.0 Preview (M9) Download, or check the latest working version.
To download the JUnit sources:
1. Download the JUnit source code from CVS repository to the <junit_src_root> directory. CVSROOT=:pserver:email@example.com:/cvsroot/junit. You need to download the junit directory.
To create the JUnit NetBeans Project:
1. From the main menu, choose File > New Project.
The New Project wizard opens.
2. In the Categories list, select "Java", in the Projects list, select "Java Project with existing ANT Script," and click Next.
3. At the Name and Location page, specify the locations of the JUnit's project files and the build.xml file. In this case, the JUnit project files are located at C:\tmp\junit\.
4. At the Build and Run Actions page, the IDE sets the following Ant targets in the fields listed below:
Change the value of Test Project field to dist.
5. At the Source Package Folders page of the wizard, specify <junit_src_root>/src as the source package folder.
6. Click the Includes/Exludes button and specify the following values in the fields listed below:
Note: This step is required because you do not need certain packages from the JUnit source. Examine build Ant task in the JUnit's build.xml to ensure you should exclude the packages mentioned above.
7. At the Java Sources Classpath page, add the hamcrest-core-1.1.jar file under the <junit_src_root>/lib directory to the Java Sources Classpath list.
The Projects window contains the project node for the JUnit project you have just created. Now you can develop JUnit within the NetBeans IDE.
To compile the JUnit project files, do the following:
1. In the Projects window, right-click the JUnit project node and choose Build or Clean and Build from the pop-up menu.
The JUnit source code is compiled and you see the "BUILD SUCCESSFUL" message in the Output window.
To perform testing of the JUnit project, do the following:
1. In the Projects window, right-click the JUnit project node and choose Test from the pop-up menu, or press Alt+F6.
A test run of the JUnit project is performed and you see test results in the Output window.
In this tutorial, you learned how to start JUnit development in the NetBeans IDE. You have completed the following exercises: