Creating and Running Tests


IDE project templates are set up with unit testing in mind. Most project types set up a folder for unit tests next to the folder containing your sources. You can have the IDE generate skeleton code for a class's unit test and place it within the test folder with a package structure corresponding to that of the class to be tested.

To generate unit test code for a class:

  1. In the Projects window, right-click the class you want to create a test for and choose Tools | Create JUnit Tests (Ctrl-Shift-U).

  2. In the Create Tests dialog box, set a class name and location, and specify the code generation options for the test.

    By default, the class name is filled in for you and corresponds to the name of the class being tested with Test appended to the name. The test class is placed in a test folder that has the same package structure as your sources.

    If you later add some new methods to your class, you can choose the Create Tests command again. Test methods for the new methods will be added to the existing test class.

To run the selected project's tests, press Alt-F6 or choose Run | Test "ProjectName".

To run a test for a specific file, select the file in the Source Editor or Projects window and press Ctrl-F6 or choose Run | Run File | Test "Filename".



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net