Tester Quick Reference

Unit testing framework for OpenForum with fluent-style interface

Key Features Test Pattern Tests follow a three-stage pattern:
  1. given - Set up test data
  2. when - Execute the action/method under test
  3. then - Assert expected output
Server-Side Usage: // Import the test framework var tester = js.getObject("/OpenForum/AddOn/Tester","Test.sjs"); // Create a class to test var MyTestClass = function() { this.increment = function(value) { return value 1; }; this.decrement = function(value) { return value-1; }; }; // Wrap the function under test function testMyClass(fn) { return function (input) { return MyTestClass[fn](input); }; } // Log message about the test tester.log("Running tests for MyTestClass"); // Create test instance tester.unitTest("Can add one to a number"). given(122). when( testMyClass("increment") ). thenOutputEquals(123). run(); // Another test tester.unitTest("Can subtract one from a number"). given(123). when( testMyClass("decrement") ). thenOutputEquals(122). run(); // Get results var results = tester.getResults(); tester.log("Tests:" results.tests " Passed:" results.passed " Failed:" results.failed); Test Methods Running Tests Via Tester Client: /OpenForum/AddOn/Tester?pageName=/MyPage&testFileName=test.sjs Via URL Action: /OpenForum/AddOn/Tester?action=runTest&pageName=/MyPage&testScript=test.sjs Test Results Format { tests: 2, passed: 1, failed: 1 } Example Test Output Test Results Starting MESSAGE: Started Tester v0.002 The Jester MESSAGE: Running tests for MyTestClass PASSED: Can add one to a number FAILED: Can subtract one from a number. Input (123) Expected (122) but found (124) MESSAGE: Tests:2 Passed:1 Failed:1 Full Reference