This lesson explains the basics of the guided test creation process. You will learn how to use UTA to:

  • create a test,
  • instantiate objects,
  • update the test code,
  • isolate the test,
  • improve the test,
  • make assertions.

In this lesson, you will create a unit test for the apply() method, which takes a transaction object. Creating a unit test for this method and isolating the test from its dependencies may be tedious and complex. Unit Test Assistant will guide to create an isolated test easier and faster.

  1. In the Package Explorer, to go jtest-examples> src/main/java> examples> nbank.
  2. Double-click Account.java to open the class in the editor.
  3. Click anywhere within the apply() method.

              
  4. Click the Regular action in the Unit Test Assistant view to create a JUnit test and automatically perform the initial test setup.

        
    The test includes declarations of the required objects and variables, as well as default values indicated by comments.

      
  5. Select the line that contains the 'customer' object and lick Instantiate "customer" action in the Unit Test Assistant view to instantiate the object.

    UTA will automatically update the test code:

                                        
  6. Replace the default UTA values with meaningful data, as indicated by the comments in the test code.

               
  7. Scroll down to locate the helper method that UTA automatically generated during test creation to mock the transaction object that is passed to the apply() method. UTA can use Mockito and Powermock frameworks for test isolation.


  8. Replace the default UTA values by setting the boolean to true and and updating the value of the feeResult variable.

                      
  9. Click Run testApply in the Unit Test Assistant view to execute the test.

                        
    The Recommendations view will display information that your test does not include any assertions. As the next step, you can manually add your own assertions or use UTA to generate the assertions for you by using the tracking option. It allows UTA to monitor an object and compare its state before and after the execution of a method. The insight into how particular values changed during execution enables UTA to provide you with valid assertions
                          
  10. Click Track apply action link in the 'Assertions' recommendation to monitor the method call and display available assertions.

                                     
  11. Click the Make assertions action link to update your test code with the available assertions.


  12. Rerun the test.
  • No labels