Child pages
  • JSUnit

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Div
styledisplay:none

DO NOT EDIT THE CONTENT OF THIS PAGE DIRECTLY (EXCEPT INSIDE THE DIV BELOW WITH ID=DESCRIPTION), UNLESS YOU KNOW WHAT YOU'RE DOING.
THE STRUCTURE OF THE CONTENT IS VITAL IN BEING ABLE TO AUTO UPDATE THE CONTENT THROUGH THE DOC GENERATOR.

Enter additional information related to this 'class' inside the {div} macro with 'id=description'

function setUp() { //Code here to setup the environment for the testcases in this scope } function tearDown() { //Code here to cleanup the environment after running the testcases in this scope }

See Unit Testing for more info on how to utilize the methods of the JSUnit class

 

Div
iddescription

Servoy has built-in support for Unit Testing. The integration adds the following to the Servoy environment:

  • A JSUnit node to the Solution Explorer, exposing the assert functions used in testcases
  • An entry in the content menu of the Active Solution to run the Unit Tests
  • A J(S)Unit view for viewing the results of a testrun

Creating testcases is as straightforward as creating a function with a name that starts with 'test_':

Code Block
function test_thisShouldPass() {
 jsunit.assertEquals('This test should pass', true, 5 < 10);
}

function test_thisShouldFail() {
 jsunit.assertEquals('This test should fail', true, 10 < 5);
}

The JSUnit node in the Solution Explorer provides easy access to the different supported assert functions

Testcases can be added on application level in the global scope of on form level in the form scope.

Each scope can contain a setUp and/or tearDown function. The setUp function is called BEFORE running each testcase in the scope and the tearDown function is called AFTER running each test in the scope. The setUp and tearDown function allow the developer to create the right circumstances for testcases to run and cleanup afterwards. Note that the setUp() and tearDown() methods are called before and after EACH test methods, as each single test is supposed to be independant.

Code Block



HTML Table
id
classservoy sSummary
Colgroup Tag
Col
width80px
Col
Table Head (thead)
Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Method Summary
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertEquals(expected, actual)
Asserts that two values are equal.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertEquals(message, expected, actual)
Asserts that two values are equal.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertFalse(boolean_condition)
Asserts that a condition is false.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertFalse(message, boolean_condition)
Asserts that a condition is false.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertFloatEquals(expectedFloat, actualFloat, tolerance)
Asserts that two floating point values are equal to within a given tolerance.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertFloatEquals(message, expectedFloat, actualFloat, tolerance)
Asserts that two floating point values are equal to within a given tolerance.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertMatches(regularExpression, actualString)
Asserts that a regular expression matches a string.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertMatches(message, regularExpression, actualString)
Asserts that a regular expression matches a string.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNotNull(object)
Asserts that an object is not null.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNotNull(message, object)
Asserts that an object is not null.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNotSame(notExpected, actual)
Asserts that two values are not the same.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNotSame(message, notExpected, actual)
Asserts that two values are not the same.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNotUndefined(definedObject)
Asserts that an object is not undefined.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNotUndefined(message, definedObject)
Asserts that an object is not undefined.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNull(nullValue)
Asserts that an object is null.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertNull(message, nullValue)
Asserts that an object is null.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertSame(expected, actual)
Asserts that two values are the same.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertSame(message, expected, actual)
Asserts that two values are the same.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertTrue(boolean_condition)
Asserts that a condition is true.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertTrue(message, boolean_condition)
Asserts that a condition is true.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertUndefined(undefinedValue)
Asserts that an object is undefined.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
assertUndefined(message, undefinedValue)
Asserts that an object is undefined.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
fail(message)
Fails a test.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
fail(message, instanceOfCallStack)
Fails a test.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
fail(message, instanceOfCallStack, userMessage)
Fails a test.

...