TS 60 JUnit

JUnit Test Specification

Author: Jiri Vagner, Max Sauer, Pavel Pribyl
Last update: 26.3. 2009
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.0, 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 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 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 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 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
    • EXPECTED RESULT: "JUnit Test Result" window" should look like ...
      Image:junit-result-window_TS_60_JUnit.jpg
  2. "Rerun button"
    1. In "JUnit Test Result" press the Rerun button
    • EXPECTED RESULT: The test is run again.
    • Try re-running different types of tests (Test of a whole project, test of a single file etc.)
    • *Note*: see issue 160668
    • EXPECTED RESULT: The Rerun button should work in all cases.
  3. "Filter button"
    1. In "JUnit Test Result" toggle/untoggle filter button
    • EXPECTED RESULT: Toggled filter button shows failures only in result tree.
  4. "Navigation"
    1. In "JUnit Test Result" tree doubleclick on FAILED nodes.
    • EXPECTED RESULT: It will open appropriate test file and focus failed method.
    1. Press the UP or DOWN ARROW button
    • EXPECTED RESULT: Previous/Next failure node is highlighted


Test suite: Result window popup menu

Purpose: Testing of functionality of popup menu options
Setup: Continue from previous test suite

  1. "Go to source"
    1. In "JUnit Test Result" tree invoke popup menu on FAILED node and select "Go to Source"
    • EXPECTED RESULT: It will open appropriate test file and focus failed method (same result as double-clicking on the node)
  2. "Run Again"
    1. Select "Run Again" from the failed node's popup menu
    • EXPECTED RESULT: Only the corresponding test method is run (NOT the whole test)
  3. "Debug"
    1. Go to a source code of any failed test method
    2. Place a breakpoint on any line of this method
    3. Select "Debug" from the failed node's popup menu
    • EXPECTED RESULT: The debugger is run and it stops at the breakpoint
  4. "View Difference"
    1. Select a node where the test failed because of different expected and actual value (contains text: "expected<...> but was <...>")
    2. Select "View Difference" from the node's popup menu
    • EXPECTED RESULT: New window is opened. Both values, Expected and Actual, can be seen
  5. Passed tests
    1. Select a node where the test PASSED and invoke the popup menu
    • EXPECTED RESULT: Only "Run Again" and "Debug" options are present. Both works properly.


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