Developers » Reference Tools » Unit Tests » Unit Test Segments


Unit Test Segments

Quick Links

Unit tests are comprised of three segments:

  • Context Initialization
  • Script Execution
  • Assertion Methods

We also encourage, but do not require you to add comments to your scripts and unit tests. See Coding Standards & Best Practices for more information about commenting in your code and other scripting best practices.

Context Initialization

The context initialization segment is used to define your input. Workflow automatically generates code to call the related test script, and to set the context parameter.

You need to create the case, project, user, or whichever object you want to test. Expand the factory option in the Context Info resource toolbar to display the factory method objects you can use in your script.

Script Execution

The script execution method will execute the script you defined in the context initialization segment. Workflow adds the execution method based on the script you are testing when you update the Test for Script field.

Assertion Methods

Use assertion methods to perform validations of your target script. To check if all objects result in the expected values, compare the actual value of the object with the expected value after you execute the script.

You can use these assertion methods in your unit tests:

Assert.eq(expected_value, value) //Asserts the expected value is equal.
Assert.isTrue(value) //Asserts the value is true.
Assert.isFalse(boolean_value) //Asserts that a value is false.
Assert.isNull(value) //Asserts the value is null.
Assert.isNotNull(value) //Asserts the value is not null. //Asserts the test fails with a message.

Commenting in Scripts

[Back to top]

Commenting in scripts is not required, but it is good practice to add comments to your scripting. This enables subsequent users to quickly determine the intent of the specific code.

Commenting Conventions

Workflow automatically generates comments related to your test script name and system ID when you enter a Test for Script value. We also encourage you to add your own comments as necessary.

// Comments: Single line comments start with // and the comment follows.


//Here is my single-line comment 

/*Comments*/: A multiline comment starts with /* and ends with  */ with the comment between.


/*Here is my comment that may span multiple lines. 
Enclosing them using this syntax ensures the comment is not read as code.*/