Java Reference
In-Depth Information
A JavaScript script element defines the test functions for our factorial D and regular
expression E tests. As with JU nit 3, we define test functions with the function name
prefix test . The set of JsUnit assert functions is smaller than the set of JU nit assert
methods and is listed here. Like JU nit, the API defines a version of assert functions
with and without a message argument. The square brackets in the following list
denote that the argument is optional.
assert([message,] booleanValue)
assertTrue([message,] booleanValue)
assertFalse([message,] booleanValue)
assertEquals([message,] expectedValue, actualValue)
assertNotEquals([message,] expectedValue, actualValue)
assertNull([message,] value)
assertNotNull([message,] value)
assertUndefined([message,] value)
assertNotUndefined([message,] value)
assertNaN([message,] value)
assertNotNaN([message,] value)
fail(message)
Like JU nit, JsUnit lets you use setUp and tearDown functions. JsUnit calls your
setUp function before each test function and your tearDown function after each
test function.
JsUnit supports an equivalent to @BeforeClass if you define a function called set-
UpPage . JsUnit calls setUpPage once after the page is loaded but before it calls any test
functions. When your setUpPage function ends, it must set the variable setUpPage-
Status to 'complete' to indicate to JsUnit that it can proceed to execute the page.
JsUnit versus JUnit
JsUnit differs from JUnit in that JsUnit doesn't define the order of test function
invocation; in JUnit, the order of methods in the source file defines the invoca-
tion order.
In addition, although JUnit creates a new test object instance to invoke each
method, JsUnit doesn't use a corresponding action, like reloading the page, which
means that JsUnit preserves page-variable values across test function invocations.
13.4.4
Writing JsUnit test suites
As in JU nit, you can group JsUnit tests into a suite of related tests. Listing 13.6 wraps
our previous test page into a test suite.
 
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search