JSUnit
(jsunit)
Overview
The JSUnitAssertFunctions
class provides a comprehensive set of assertion methods for unit testing in Servoy. It supports operations such as equality checks, regular expression matching, null checks, and conditional assertions. These methods enable the validation of test outcomes with detailed messages and tolerances for specific scenarios like floating-point comparisons. Assertions can evaluate conditions as true or false, verify object definitions, or ensure two values are the same or different. Additional functions allow forcing test failures and checking against expected exceptions.
Methods Summarized
void
Asserts that two values are equal.
void
Asserts that two values are equal.
void
Asserts that a condition is false.
void
Asserts that a condition is false.
void
Asserts that two floating point values are equal to within a given tolerance.
void
Asserts that two floating point values are equal to within a given tolerance.
void
Asserts that a regular expression matches a string.
void
Asserts that a regular expression matches a string.
void
Asserts that an object is not null.
void
Asserts that an object is not null.
void
Asserts that two values are not the same.
void
Asserts that two values are not the same.
void
Asserts that an object is not undefined.
void
Asserts that an object is not undefined.
void
Asserts that an object is null.
void
Asserts that an object is null.
void
Asserts that two values are the same.
void
Asserts that two values are the same.
void
Asserts that a condition is true.
void
Asserts that a condition is true.
void
Asserts that an object is undefined.
void
Asserts that an object is undefined.
void
Fails a test.
void
Fails a test.
void
Fails a test.
Methods Detailed
assertEquals(expected, actual)
Asserts that two values are equal. AssertionFailedError is thrown if the actual value does not match the regular expression.
Parameters
Returns: void
Sample
assertEquals(message, expected, actual)
Asserts that two values are equal. AssertionFailedError is thrown if the actual value does not match the regular expression.
Parameters
String message The test description/message.
Object expected the expected value.
Object actual the actual value.
Returns: void
Sample
assertFalse(boolean_condition)
Asserts that a condition is false. AssertionFailedError is thrown if the evaluation was not false.
Parameters
Boolean boolean_condition the actual value.
Returns: void
Sample
assertFalse(message, boolean_condition)
Asserts that a condition is false. AssertionFailedError is thrown if the evaluation was not false.
Parameters
Returns: void
Sample
assertFloatEquals(expectedFloat, actualFloat, tolerance)
Asserts that two floating point values are equal to within a given tolerance. AssertionFailedError is thrown if the expected value is not within the tolerance of the actual one.
Parameters
Number expectedFloat the expected value.
Number actualFloat the actual value.
Number tolerance tolerance when comparing.
Returns: void
Sample
assertFloatEquals(message, expectedFloat, actualFloat, tolerance)
Asserts that two floating point values are equal to within a given tolerance. AssertionFailedError is thrown if the expected value is not within the tolerance of the actual one.
Parameters
String message The test description/message.
Number expectedFloat the expected value.
Number actualFloat the actual value.
Number tolerance tolerance when comparing.
Returns: void
Sample
assertMatches(regularExpression, actualString)
Asserts that a regular expression matches a string. AssertionFailedError is thrown if the expected value is not the actual one.
Parameters
Object regularExpression the regular expression used for matching.
String actualString the actual value to be matched.
Returns: void
Sample
assertMatches(message, regularExpression, actualString)
Asserts that a regular expression matches a string. AssertionFailedError is thrown if the expected value is not the actual one.
Parameters
String message The test description/message.
Object regularExpression the regular expression used for matching.
String actualString the actual value to be matched.
Returns: void
Sample
assertNotNull(object)
Asserts that an object is not null. AssertionFailedError is thrown if the object is not null.
Parameters
Object object the actual value.
Returns: void
Sample
assertNotNull(message, object)
Asserts that an object is not null. AssertionFailedError is thrown if the object is not null.
Parameters
Returns: void
Sample
assertNotSame(notExpected, actual)
Asserts that two values are not the same. AssertionFailedError is thrown if the expected value is the actual one.
Parameters
Returns: void
Sample
assertNotSame(message, notExpected, actual)
Asserts that two values are not the same. AssertionFailedError is thrown if the expected value is the actual one.
Parameters
String message The test description/message.
Object notExpected the value that is not expected.
Object actual the actual value.
Returns: void
Sample
assertNotUndefined(definedObject)
Asserts that an object is not undefined. AssertionFailedError is thrown if the object is undefined.
Parameters
Object definedObject the actual value.
Returns: void
Sample
assertNotUndefined(message, definedObject)
Asserts that an object is not undefined. AssertionFailedError is thrown if the object is undefined.
Parameters
Returns: void
Sample
assertNull(nullValue)
Asserts that an object is null. AssertionFailedError is thrown if the object is not null.
Parameters
Object nullValue the actual value.
Returns: void
Sample
assertNull(message, nullValue)
Asserts that an object is null. AssertionFailedError is thrown if the object is not null.
Parameters
Returns: void
Sample
assertSame(expected, actual)
Asserts that two values are the same. AssertionFailedError is thrown if the expected value is not the actual one.
Parameters
Returns: void
Sample
assertSame(message, expected, actual)
Asserts that two values are the same. AssertionFailedError is thrown if the expected value is not the actual one.
Parameters
String message The test description/message.
Object expected the expected value.
Object actual the actual value.
Returns: void
Sample
assertTrue(boolean_condition)
Asserts that a condition is true. AssertionFailedError is thrown if the evaluation was not true.
Parameters
Boolean boolean_condition the actual value.
Returns: void
Sample
assertTrue(message, boolean_condition)
Asserts that a condition is true. AssertionFailedError is thrown if the evaluation was not true.
Parameters
Returns: void
Sample
assertUndefined(undefinedValue)
Asserts that an object is undefined. AssertionFailedError is thrown if the object is defined.
Parameters
Object undefinedValue the actual value.
Returns: void
Sample
assertUndefined(message, undefinedValue)
Asserts that an object is undefined. AssertionFailedError is thrown if the object is defined.
Parameters
Returns: void
Sample
fail(message)
Fails a test. AssertionFailedError is always thrown.
Parameters
String message The test description/message. This is usually the only parameter specified when calling this method.
Returns: void
Sample
fail(message, instanceOfCallStack)
Fails a test. AssertionFailedError is always thrown.
Parameters
String message The test description/message. This is usually the only parameter specified when calling this method.
Object instanceOfCallStack an internal JSUnit call stack. Use null for this if you want to get to the next optional parameter. Usually not specified.
Returns: void
Sample
fail(message, instanceOfCallStack, userMessage)
Fails a test. AssertionFailedError is always thrown.
Parameters
String message The test description/message. This is usually the only parameter specified when calling this method.
Object instanceOfCallStack an internal JSUnit call stack. Use null for this if you want to get to the next optional parameter. Usually not specified.
String userMessage a user message. Usually not specified.
Returns: void
Sample
Last updated