Creating JUnit Tests from Contextual Menu (release E)

Author: Rudolf Bock
Version: 1.42e

Dates: January 19th

Table of Contents:


This is an update for the UI specification "Creating JUnit Tests from Contextual Menu", which reflects the state of implementation in NetBeans Release E. This document covers the essential functions specified in the original UI Specification and can be taken as a interim UI spec.

In NetBeans exist several ways of how to initiate creation of test classes. You can use the Wizard and create an Empty Test Case, simple Test Case for specified Class or a Simple Test Suite.

Another way how create a test class, is select a source class or Package -> invoke the context menu and select items "Tools/JUnit Tests/Create Tests". In this case opens a dialog window with corresponding configuration form. You can set the basic parameters of the created test class using checkboxes. You can set the name of the created test class, you can also set the Location, where the created class should be placed.

The New User Interface

Thru the Contextual Menu in "Projects" or "Files" windows can be created test classes for different sources. As source can be used a single source class, the whole source folder or a Package. It should even be possible to create a test class for any existing test classes. The User Interface of the windows "Projects" and "Files" allows select a single item of the displayed list or several items contemporaneously. In this way comes to several default situations which predate the creating of a Test Class(es).

For example:

1. The Source Packages folder is selected
2. Some Package is selected
3. Only one class inside the folder Source Packages is selected
4. More than one source classes are selected (even in several Packages)
5. Any of existing test classes are selected
6. Some source and test classes are selected

To cover all of the mentioned states, is necessary to extend the current user interface. This modifications are related to the submenu "JUnit Tests" in the menu "Tools" and the "Create Tests" dialog.

Items in this submenu can be selected trough the contextual menu "Tools" in the windows "Projects", "Files" and "Favorites" or from the main menu. The picture shows the structure of this menu with assigned shortcuts. This shortcut can be platform depended, but on all platforms it should be similar to the other items in this submenu.

The chosen items in the Project Window influencing the behavior and window title of the dialog. If the user select any existing test classes or test package, the window title is "Create Test Suite". In other cases the window title remain "Create Tests".

Bellow displayed picture shows the new "Create Tests" dialog. The center part of the form has a similar functionality like the current (previous) version. If you create a test class for a Package, you can specify the Class Types. In other cases these checkboxes doesn't figure in the form. Content or behavior of the sections A, B, C, D can change in dependence of the user interaction or created test class.

     Create test class for a concrete source class.Create tests for the whole source package.

Section A: This place shows an information about the source for the created test class. If the source is a specific/selected source class, the displayed text looks like "Class to Test: <some_java>". If the specified source is a Package, the displayed text can be "Package: <any_java_package>", Section C is displayed (picture on the right). If the source consists from several classes, the displayed text should be "More than one class is selected..." and the Section C is displayed.

Section B: User can set a name of the created test class here, with the pop-up menu "Location:" he can select a destination folder for the test class and finally he can choose a destination Package from the combobox "Package:". This last interface element should be enabled only when you create a Test Suite for some existing Test Classes. In this case should be possible to specify the target Package for the created Test Class. If only one source class is selected, the combobox "Package:" shows the name of the corresponding Test Package, which will contain the newly created test class. If you select more than one source class or a Package, the combobox "Package:" displays nothing or just a "-" and should be disabled (dimmed - no only not editable). The Location combobox offers only destinations, which would be searched by the projects infrastructure when trying open or run a test for the specified class(es).
If the user enter a non-default class name, the project infrastructure might not be able to find the class when it would be about to be executed. Therefore the user must be informed about that via message area D (explained later).
If the field Class name is empty or any invalid characters are entered, the OK button must be disabled and the user will be warned via the message area D.

Section C: These UI elements are visible only when you create a Test Suite for a Package, Source Package folder or more than one source class - similarly to the current dialog.

Section D: This area is reserved for warnings and user-interaction depended informations. You can find a similar area in the Wizard form. In contrast to the Wizard dialog, the info area is placed next to the Section B, because is important, that the user acknowledge the consequence of some settings. When a message is to be displayed that would not fit i one line, the message text is wrapped and this section (and the whole dialog to) is automatically resized so, that the message fits.

Some note to creating tests using the JUnit Wizard

The JUnit test classes can be created also using a Wizard. This could be invoked thru the menu item New File... His functionality is mostly similar to the Create Tests dialog described above. The next picture shows this similarity. You can see the same sections A,B and D, which behaves in the same way.

But there still a few design flaws, which should be solved.

1. The Wizard form for creating test classes includes fields where you can type data and another for display purposes only. The second mentioned kind of elements represent a problem. While in Windows these elements look like disabled - not enterable, on the MacOS X they behave like read-only. This means, that these element are enterable, but you can't make any changes. Even you can't copy content from these enterable/read-only fields to the clipboard. This is a little bit confusing.

Suggested solution: On all platforms should be these elements disabled. These element should look dimmed. The property "enabled" should be set FALSE (look at the picture "New Test for Existing Class")

2. The picture bellow show a Wizard form page, where in the bottom of the screen a warning message is displayed (section D). But unfortunately you can't read it completely, because the text isn't wrapped. Even if you resize the window to full screen can happen, that the displayed text don't fit.

Suggested solution: Verify, if in all forms that are use a Warning/Info UI element (mostly resizable Wizard screens or preference dialogs etc.), the display settings for these elements are set to TEXT WRAP.

Project Features

About this Project

Usersguide was started in November 2009, is owned by kganfield, and has 64 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
Please Confirm