TS 70 JUnit

JUnit Test Specification

Author: Peter Pis
Now managed by: Andrey Komarov
Last update: 26.08.2008
Introduction: This document contains test specifications for JUnit module.
Comments: JUnit module is an extension to JUnit framework and serves in NetBeans IDE as support for creating unit tests of individual classes or whole packages. It generates skeletons of those unit tests and allows to run tests directly from tested classes or packages.

Contents


Test suite: Selecting jUnit version

Purpose: In NB 6.5, there is a new support for new jUnit version 4.x. This testsuite tests selecting dialog

  1. "Source levels without anotations (1.4, 1.3, ...)"
    1. Create new Java Application project
    2. Select new project node in Project tab, invoke popup menu and click "Properties" menu item
    3. In category Sources change "Source Level" listbox value to "1.4" and press "OK" button
    4. Select Main.java node in Project tab and try to create test for this class (CTRL + SHIFT + U)
    • EXPECTED RESULT: jUnit version support was not set yet, so thats why you can see jUnit version chooser. You are not able to choose jUnit 4.x, because jUnit reqeuires Java 1.5+.
  2. "Source levels with anotations (1.5, 1.6)"
    1. Press "Cancel" button or hit ECS key
    2. Again select new project node in Project tab, invoke popup menu and click "Properties" menu item
    3. In category Sources change "Source Level" listbox value to "1.5" and press "OK" button
    4. Select Main.java node in Project tab and try to create test for this class (CTRL + SHIFT + U)
    • EXPECTED RESULT: jUnit version support was not set yet, so thats why you can see jUnit version chooser. Now you are able to choose jUnit 4.x or jUnit3.x support.
    1. Choose jUnit3.x or jUnit4.x support and press OK
    2. In "Create Tests" dialog just press OK
    • EXPECTED RESULT: Test class was created.
    1. Add new class into project
    2. Select new class node in Project tab and try to create test for this class (CTRL + SHIFT + U)
    • EXPECTED RESULT: jUnit version support has been already set, version chooser will not be displayed. You can see only "Create tests" dialog.


Test suite: Create test(s) from popup-menu

Purpose: Testing all ways how user can create test from popup menu
Setup: Open File:SampleJUnitProject.zip SampleJUnitProject project and expand "sampleproject" package

  1. Create simple jUnit test with all methods
    1. Select Knizka.java node in Project tab
    2. Invoke popupmenu and click "Tools" -> "Create JUnit Tests" menu item
    3. iN jUnit version choose dialog choose jUnit3.x or jUnit4.x support and press OK
    4. Check all checkboxes on form and press "OK" button
    • EXPECTED RESULT: New test class KnizkaTest.java was generated. Check its content. File should contains setUp and tearDown methods (jUnit3.x: tearDown() and setUp() methods, jUnit4.x: methods with @Before and @After annotation) and a lot of test methods (jUnit3.x: methods with prefix "test...()", jUnit4.x: methods with @Test annotation).
  2. Create simple jUnit tests for different modificators
    1. Follow the steps of previous test case, but modify dialog's options. Try different checkbox combinations.
    • EXPECTED RESULT: Check generated source of generated test class and delete it. Repeat this test case several times.
  3. Create jUnit tests on package
    1. Delete all previously created test classes, delete all test classes from sampleproject package inside Test project node.
    2. In Project tab select "Source Packages -> sampleproject" package node
    3. Invoke popupmenu and click "Tools" -> "Create JUnit Tests" menu item
    4. In "Create tests" dialog check checkboxes for Code Generation randomly.
    • EXPECTED RESULT: Multiple JUnit TestSuit clasess should be created under the node/package "Test Packages -> sampleproject"
  4. Create jUnit test using expert options
    1. Remove generated KnizkaTest.java
    2. Change value of Expert properties in "Tools -> Options -> Advanced View -> Options -> Testing -> JUnit Tests" node to something else.
    3. Create test and suite classes.
    • EXPECTED RESULT: Generated source code should slightly differ from previous code generated by previous test case.


Test suite: Create test using "New File" wizard

Purpose: Testing templates
Setup: Setup: Open File:SampleJUnitProject.zip SampleJUnitProject project and expand "sampleproject" package

  1. Create empty test
    1. Invoke "New File" dialog (CTRL + N)
    2. Choose category "JUnit" and file type "Empty test"
    3. Press "Finish" button
    • EXPECTED RESULT: New empty test class was generated into Test Packages and was opened for editing.
  2. Create test for existing class
    1. Invoke "New File" dialog (CTRL + N)
    2. Choose category "JUnit" and file type "Test for Existing Class"
    3. Press "Next" button
    4. Type class name "sampleproject.Knizka" directly into textfield "Class to Test" or use "Browse" button and browse Knizka class.
    5. Press "Finish" button
    • EXPECTED RESULT: New test class for selected class was generated into Test Packages and was opened for editing.
  3. Create empty test suite
    1. Invoke "New File" dialog (CTRL + N)
    2. Choose category "JUnit" and file type "Test Suite"
    3. Press "Next" button
    4. Press "Finish" button
    • EXPECTED RESULT: New test suite file was generated.
  4. Create test suite for package
    1. Invoke "New File" dialog (CTRL + N)
    2. Choose category "JUnit" and file type "Test Suite"
    3. Press "Next" button
    4. Choose "sampleproject" test package from "Package" listbox
    5. Press "Finish" button
    • EXPECTED RESULT: New test suite for test classes from selected test package was generated.


Test suite: Navigation

Purpose: To test navigation between test and tested class.
Setup: Setup: Setup: Open File:SampleJUnitProject.zip SampleJUnitProject project and generate test for "Kolo" class.

  1. Open test for selected class
    1. Close all opened files in the Editor (CTRL + SHIFT + F4)
    2. Open KoloTest.java test class
    3. Go to main menu and click "Navigate -> Go to tested class" or press CTRL + SHIFT + T
    • EXPECTED RESULT: Class Kolo.java should be opened and focused in the Editor.
    1. Close all opened files in the Editor (CTRL + SHIFT + F4)
    2. Open Kolo.java class
    3. Go to main menu and click "Navigate -> Go to test" or press CTRL + SHIFT + T
    • EXPECTED RESULT: Test class KoloTest.java should be opened and focused in the Editor.


Test suite: Run Test

Purpose: Testing of 'Test Project' JUnit feature.
Setup: Setup: Setup: Open File:TS 60 JUnitSampleJUnitProject.zip SampleJUnitProject project and generate tests for Kolo and Knizka classes.

  1. "Run tests"
    1. Open test class KnizkaTest.java and remove content of a few test methods.
    2. Create new empty test class using "New File" wizard and add to this class empty test method foo();
    3. Invoke popupmenu above "SamplejUnitProject" project node and click "Test Project" menu item
  2. "Filter button"
    1. In "JUnit Test Result" toggle/untoggle special filter button from left top window corner.
    • EXPECTED RESULT: Toggled filter button shows failures only in result tree.
  3. "Navigation"
    1. In "JUnit Test Result" tree doubleclick on FAILED nodes.
    • EXPECTED RESULT: It will open appropriate test file and focus failed method.


Test suite: Run single test case

Purpose: Testing of "running single test case JUnit" feature.
Setup: Open File:TS 60 JUnitSampleJUnitProject.zip SampleJUnitProject project and generate tests for Kolo and Knizka classes. Previous test suite should be finished.

  1. "Test case - PASSED"
    1. In "JUnit Test Result" select some test case that passed.
    2. Invoke "Run Again" popup menu action on test case node.
    • EXPECTED RESULT: Test should be run. When it finishes "JUnit Test Result" lists only executed test case that should pass.
  2. "Test case - FAILED"

Setup: "Run Test" suite should be finished.

    1. In "JUnit Test Result" select some test case that failed.
    2. Invoke "Run Again" popup menu action on test case node.
    • EXPECTED RESULT: Test should be run. When it finishes "JUnit Test Result" lists only executed test case that should fail.


Test suite: Debug single test case

Purpose: Testing of "debugging single test case JUnit" feature.
Setup: Open File:TS 60 JUnitSampleJUnitProject.zip SampleJUnitProject project and generate tests for Kolo and Knizka classes. "Run Test" suite should be finished.

  1. "Test case - PASSED"
    1. In desired test case that passed put a breakpoint.
    2. In "JUnit Test Result" select this test case and invoke "Debug" popup menu action.
    • EXPECTED RESULT: Debugging of test case should be started. It should hit the breakpoint. Finish debugging session.
  2. "Test case - FAILED"

Setup: "Run Test" suite should be finished.

    1. In desired test case that failed put a breakpoint.
    2. In "JUnit Test Result" select this test case and invoke "Debug" popup menu action.
    • EXPECTED RESULT: Debugging of test case should be started. It should hit the breakpoint. Finish debugging session.


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