This lesson explains how to create and make assertions for multiple test cases for one or more methods.

Exercise 1 - Creating Tests for Multiple Methods in a Class

  1. In your IDE, choose Parasoft> Preferences> Unit Test Assistant in the menu bar.
  2. Disable the Generate sample assertions option and click OK.

             
  3. Open the jtest-examples> src/main/java> examples.junit> MoneyBag class in the editor and click anywhere in the class.
  4. Choose the Add test case(s) action in the UTA interface.

            
  5. Select all the listed methods in the dialog that opens and click OK. UTA will create a test class MoneyBagTest.java that includes tests for all the selected methods.

                      
  6. Open the MoneyBagTest.java class in the editor and click anywhere in the class.
  7. Choose the Track and make assertions action in the UTA interface. UTA will run all the tests from the MoneBagTest class and update the test code with the recommended assertions.

     

    When the run is completed, UTA displays the number of updated tests and the total number of the assertions that were added during the run. The tests that fail are not updated.



  8. Open the MoneyBagTest.java file to verify that the assertions were added.

Exercise 2 - Creating Tests for Multiple Methods in a Package  

  1. In your IDE, right-click the jtest-examples> src/main/java> examples.mock package.
  2. Select Unit Testing> Add test case(s) from the menu.

        
  3. Click OK in the dialog that opens. UTA will create tests for the methods in the package.


  4. In your IDE, right-click the jtest-examples> src/test/java> examples.mock package.

                       
  5. Select Unit Testing> Track and make assertions from the menu. UTA will run all the tests from the examples.mock package update the test code with the recommended assertions.

        
    When the run is completed, UTA displays the number of updated test classes and test cases, as well as the total number of the assertions that were added during the run. The tests that fail are not updated.

              
  6. Open jtest-examples> src/main/java> examples.mock> MultiSourceCharacterReader.java to verify that the assertions were added.


  • No labels