Developers » Reference Tools » Unit Tests » Unit Test Script Example » Unit Test for Set Assignee by Amount


Unit Test for Set Assignee by Amount

To create the unit test for the script Set Assignee by Amount created in the previous section:

  1. See Create New Unit Test for detailed information on creating unit tests.

  2. Create a new Unit Test type script.

  3. For this example, we will name the unit test: Unit Test Set Assignee by Amount.

  4. Enter Set Assignee by Amount in the Test for Script field. This field is not required to correctly run the test, but it is helpful to see which script the unit test will test for when you later review the unit test information.

  5. Workflow will generate partial syntax in the code window. We will replace this syntax with the following code. Notice the use of the three required segments: Context Initialization, Script Execution, and Assertion Methods

//Context initialization (defining input)
def caze = factory.newCase(); 
def form = factory.newForm(caze);
def script = resp.script.get('set_assign_by_amount') 
script.setContextParam("resp", resp) 
script.setContextParam("form", form) 
script.setContextParam("currentCase", caze) 

//Initialize amount (simulating that user filled the field on the form)
form.setValue('amount', 1000);

//Script Execution

Assert.isNotNull( form.getField("amount") );
Assert.isNotNull( form.getField("amount").value );

//Use case when value is greater then 1000
form.setValue('amount', 1001);

//Script Execution

Assert.eq(1001, (int)form.getField("amount").value );
Assert.eq('smith', caze.getAssignee().getLoginName() );
//Use case when value is less then 1000
form.setValue('amount', 999);

//Script Execution

Assert.eq(999, (int)form.getField("amount").value );
Assert.eq('admin', caze.getAssignee().getLoginName() );

  1. Click Run Test to check the unit test. Workflow displays the results of the test in the Output tab below the code window.
  2. Save your new unit test.