Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space ENGINES1031 and version 10.3.4

...

  • manually add the @jtest.factory tag to the Javadoc comment for the method
  • select a method in the editor, and use the Tag Factory Methodfactory method action in the Unit Test Assistant interface; this will automatically add the @jtest.factory tag to the Javadoc comment for the selected method, and update the Factory Methods view with the tagged method.
    Image Removed

The tagged methods will be used when you:

  • create multiple test cases with the Add test case(s) action (see Creating Multiple Unit Tests) if a relevant factory method is available for the type that needs to be initialized,
  • instantiate the object with the Instantiate using factory action from the Unit Test Assitant view (the action will show up when a relevant factory method is available for the selected type).
  • Image Added

In the following example, the createMyObject method is tagged:

...

Code Block
public class TestUtil {
    /**
     * @jtest.factory
    */
    public static MyObject createMyObject() {
        return MyObjectFactory.createMyObject(3);
    }
}

...

Untagging Factory Methods

...

  • manually remove the tag from the Javadoc,
  • select a tagged method in the editor, and then use the Untag Factory Methodfactory method action in the Unit Test Assistant interface; this will automatically update the Javadoc, and remove the method from the Factory Methods view,
    Image RemovedImage Added
           
  • right-click a method in the Factory Methods view, and choose the Untag Factory Methodfactory method(s) option; this will automatically update the Javadoc, and remove the method from the Factory Methods view.
    Image RemovedImage Added

    If you select one or more class, package, or project, choosing the Untag Factory Methodfactory method(s) option will remove all @jtest.factory tags within the selection.

...

  1. If not already open, choose Parasoft> Show View> Factory Methods from the IDE menu bar.

  2. Select a project(s) in the Package Explorer.

    Info

    UTA will not scan projects selected in the Project Explorer or the Navigator.

  3. Click the Scan workspace or Scan selected projects button in the Factory Methods menu to scan a specific project(s) or the entire workspace for factory methods:


Using Factory Methods

The factory methods that are discovered by UTA and displayed in the Factory Methods view will automatically be used during test generation when you use one of the following options:

  • Instantiate using factory in the Unit Test Assistant view. The action will show up when a relevant factory method is available for the selected type.
  • Add test case(s) in the Unit Test Assistant view, or in the context menu (see Creating Multiple Unit Tests) if a relevant factory method is available for the type that needs to be initialized. If more than one factory method is available for a specific type, UTA will prioritize factory methods whose return type is the closest match to the type of the variable being initialized.  UTA will also prefer factory methods in the same package or in the closest parent package.