silUnit Annotations
BackgroundÂ
As you may have gathered from the name, "silUnit" was inspired by JUnit, the testing suite for Java. Just as found in JUnit, silUnit makes use of annotations to lets the silUnit suite know which routines are intended as tests or features such as running routines before each tests. Below is a brief description of each supported annotation and what they do.
/** TEST **/ -Â Test
This basic annotation lets the silUnit Suite know that the routine that follows is intended as a test. For example:
/** TEST **/
function itSaysHello() {
    assertEquals(sayHello(), "hello");
} |
 /** BEFORE **/ - Routine to Be Run Once
This annotation tells the silUnit Suite that the routine is to be run once before the rest of the tests. This is useful if you would like to set up one scenario before testing routines in a series. For example:
include "Includes/_silUnit.incl";
Â
Â
number value;
Â
Â
/** BEFORE **/
function runOnce() {
    value = 0;
}
Â
Â
/** TEST **/
function incrementOnce() {
    value++;
    assertEquals(value, 1);
}
Â
Â
/** TEST **/
function incrementAgain() {
    value++;
    assertEquals(value, 2);
} |
/** AFTER **/ - Routine to Be Run Once After a Series of Tests
The "AFTER" annotation tells the silUnit Suite to run the routine after the tests have been completed. This is useful to change the value tested to its original state. Let's say, for example, that we would like to do some testing on a custom field, but would like for that value to return to its original state. We could first use the "BEFORE" annotation to set up the test, then the "AFTER" annotation to set the value back to the original. In the example below, imagine we have a custom field called "textField" and we would like to set the value of textField, test that the transaction was successful, then revert the value of textField to its original state.
include "Includes/_silUnit.incl";
Â
string key =Â "DEMO-1";
string originalValue;
Â
/** BEFORE **/
function getOriginalValue() {
    originalValue = key.textField;
}
Â
/** AFTER **/
function setToOriginalValue() {
    %key%.textField = originalValue;
}
Â
/** TEST **/
function setTextField() {
    %key%.textField = "test";
    assertEquals(key.textField, "test");
} |
/** BEFOREEACHÂ **/ - Routine to Be Run Once Before Every Test
The "BEFOREEACH" annotation tells the silUnit Suite to run the following routine once before each test. Let's say we wanted to reset the value of a custom field before every test. The code would look something like:
/**Â AFTEREACHÂ **/ - Routine to Be Run Once After Every Test
The "AFTEREACH" annotation tells the silUnit Suite to run the following routine once after every test. This is useful for cleanup after every test.
Additional Help
Need help implementing unit tests on your script? Talk to me directly to me by clicking on the bot on this page.Â
Related articles
Filter by label
There are no items with the selected labels at this time.