Jala Test

## Class jala.Test

    Object
       |
       +--jala.Test

class jala.Test

Provides various methods for automated tests. This is essentially a port of JSUnit (http://www.edwardh.com/jsunit/) suitable for testing Helma applications.
Defined in Global/jala.Test.js

Nested Class Summary
`<static class>` | `jala.Test.Exception`
`<static class>` | `jala.Test.TestException`
`<static class>` | `jala.Test.ArgumentsException`
`<static class>` | `jala.Test.EvaluatorException`
`<static class>` | `jala.Test.TestResult`
`<static class>` | `jala.Test.TestFunctionResult`
`<static class>` | `jala.Test.HttpClient`
`<static class>` | `jala.Test.DatabaseMgr`
`<static class>` | `jala.Test.SmtpServer`

Field Summary
`Number` | `functionsFailed` Contains the number of test functions that failed
`Number` | `functionsPassed` Contains the number of test functions that passed
`Array` | `results` An Array containing the results of this Test instance.
`Boolean` | `testsFailed` Contains the number of tests that failed
`Number` | `testsRun` Contains the number of tests that were executed
`<static> <final> String` | `FAILED` Constant indicating "failed" status
`<static> <final> String` | `PASSED` Constant indicating "passed" status

Constructor Summary
`jala.Test ()` Constructs a new Test instance.

Method Summary
`void` | `assertEqual(<Object> val1, <Object> val2)` Checks if the values passed as arguments are equal.
`void` | `assertEqualFile(<Object> val, <String|helma.File> file)` Checks if the value passed as argument equals the content of a file on disk.
`void` | `assertFalse(<Object> val)` Checks if the value passed as argument is boolean false.
`void` | `assertMatch(<String> val, <RegExp> rxp)` Checks if the regular expression matches the string.
`void` | `assertNaN(<Object> val)` Checks if the value passed as argument is NaN.
`void` | `assertNotEqual(<Object> val1, <Object> val2)` Checks if the values passed as arguments are not equal.
`void` | `assertNotNaN(<Object> val)` Checks if the value passed as argument is not NaN.
`void` | `assertNotNull(<Object> val)` Checks if the value passed as argument is not null.
`void` | `assertNotUndefined(<Object> val)` Checks if the value passed as argument is not undefined.
`void` | `assertNull(<Object> val)` Checks if the value passed as argument is null.
`void` | `assertStringContains(<String> val, <String> str)` Checks if the value passed as argument contains the pattern specified.
`void` | `assertThrows(<Object> func, <Object> exception)` Checks if the function passed as argument throws a defined exception.
`void` | `assertTrue(<Object> val)` Checks if the value passed as argument is boolean true.
`void` | `assertUndefined(<Object> val)` Checks if the value passed as argument is undefined.
`String` | `directory_macro()` Returns the absolute path to the directory containing the tests
`void` | `execute(<String|Array> what)` Main test execution function
`void` | `executeTest(<helma.File> testFile)` Executes a single test file
`Object` | `executeTestFunction(<String> functionName, <helma.scripting.rhino.GlobalObject> scope)` Executes a single test function
`void` | `list_macro()` Renders the list of available tests
`void` | `renderResult(result)` Renders the result of a single test
`void` | `renderResults()` Renders the results of all tests done by this test instance to response.
`void` | `results_macro()` Renders the test results
`<static> Boolean` | `argsContainComment(<Array> args, <Number> argsExpected)` Returns true if the arguments array passed as argument contains an additional comment.
`<static> Boolean` | `evalArguments(<Object> args, argsExpected)`
`<static> String` | `getComment(<Array> args, argsExpected)` Cuts out the comment from the arguments array passed as argument and returns it.
`<static> String` | `getStackTrace(<java.lang.StackTraceElement> trace)` Creates a stack trace and parses it for display.
`<static> helma.File` | `getTestFile(<String> fileName)` Returns the testfile with the given name
`<static> Array` | `getTestFiles()` Returns an array containing the test files located in the directory.
`<static> helma.File` | `getTestsDirectory()` Returns the directory containing the test files.
`<static> Object` | `getValue(<Array> args, argsExpected, <Number> idx)` Returns the argument on the index position in the array passed as arguments.
`<static> void` | `include(<Object> scope, file)` Evaluates a javascript file in the global test scope.
`<static> String` | `valueToString(val)` Helper method useable for displaying a value

Field Detail

### functionsFailed

    Number functionsFailed

Contains the number of test functions that failed

### functionsPassed

    Number functionsPassed

Contains the number of test functions that passed

### results

    Array results

An Array containing the results of this Test instance.

### testsFailed

    Boolean testsFailed

Contains the number of tests that failed

### testsRun

    Number testsRun

Contains the number of tests that were executed

### FAILED

    <static> <final> String FAILED

Constant indicating "failed" status

See Also:
  Constant Field Values

### PASSED

    <static> <final> String PASSED

Constant indicating "passed" status

See Also:
  Constant Field Values

Constructor Detail

### jala.Test

    jala.Test()

Constructs a new Test instance.

Parameters:

`capacity` - The capacity of the cache

Method Detail

### assertEqual

    void assertEqual(<Object> val1, <Object> val2)

Checks if the values passed as arguments are equal.

Parameters:

`val1` - The value that should be compared to the second argument.

`val2` - The value that should be compared to the first argument.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertEqualFile

    void assertEqualFile(<Object> val, <String|helma.File> file)

Checks if the value passed as argument equals the content of a file on disk.

Parameters:

`val` - The value that should be compared with the content of the file on disk.

`file` - Either a file name (including a path), or an instance of helma.File representing the file to use for comparison.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertFalse

    void assertFalse(<Object> val)

Checks if the value passed as argument is boolean false.

Parameters:

`val` - The value that should be boolean false.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertMatch

    void assertMatch(<String> val, <RegExp> rxp)

Checks if the regular expression matches the string.

Parameters:

`val` - The string that should contain the regular expression pattern

`rxp` - The regular expression that should match the value

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertNaN

    void assertNaN(<Object> val)

Checks if the value passed as argument is NaN.

Parameters:

`val` - The value that should be NaN.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertNotEqual

    void assertNotEqual(<Object> val1, <Object> val2)

Checks if the values passed as arguments are not equal.

Parameters:

`val1` - The value that should be compared to the second argument.

`val2` - The value that should be compared to the first argument.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertNotNaN

    void assertNotNaN(<Object> val)

Checks if the value passed as argument is not NaN.

Parameters:

`val` - The value that should be not NaN.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertNotNull

    void assertNotNull(<Object> val)

Checks if the value passed as argument is not null.

Parameters:

`val` - The value that should be not null.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertNotUndefined

    void assertNotUndefined(<Object> val)

Checks if the value passed as argument is not undefined.

Parameters:

`val` - The value that should be not undefined.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertNull

    void assertNull(<Object> val)

Checks if the value passed as argument is null.

Parameters:

`val` - The value that should be null.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertStringContains

    void assertStringContains(<String> val, <String> str)

Checks if the value passed as argument contains the pattern specified.

Parameters:

`val` - The string that should contain the pattern

`str` - The string that should be contained

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertThrows

    void assertThrows(<Object> func, <Object> exception)

Checks if the function passed as argument throws a defined exception.

Parameters:

`func` - The function to call

`exception` - Optional object expected to be thrown when executing the function

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertTrue

    void assertTrue(<Object> val)

Checks if the value passed as argument is boolean true.

Parameters:

`val` - The value that should be boolean true.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### assertUndefined

    void assertUndefined(<Object> val)

Checks if the value passed as argument is undefined.

Parameters:

`val` - The value that should be undefined.

Throws:

- jala.Test.ArgumentsException
- jala.Test.TestException

### directory_macro

    String directory_macro()

Returns the absolute path to the directory containing the tests

Returns:

The path to the tests directory

### execute

    void execute(<String|Array> what)

Main test execution function

Parameters:

`what` - Either the name of a single test file or an array containing the names of several function files that should be executed.

### executeTest

    void executeTest(<helma.File> testFile)

Executes a single test file

Parameters:

`testFile` - The file containing the test to run

### executeTestFunction

    Object executeTestFunction(<String> functionName, <helma.scripting.rhino.GlobalObject> scope)

Executes a single test function

Parameters:

`functionName` - The name of the test function to execute

`scope` - The scope to execute the test method in

### list_macro

    void list_macro()

Renders the list of available tests

### renderResult

    void renderResult(result)

Renders the result of a single test

Parameters:

`The` - result to render

### renderResults

    void renderResults()

Renders the results of all tests done by this test instance to response.

### results_macro

    void results_macro()

Renders the test results

### argsContainComment

    <static> Boolean argsContainComment(<Array> args, <Number> argsExpected)

Returns true if the arguments array passed as argument contains an additional comment.

Parameters:

`args` - The arguments array to check for an existing comment.

`argsExpected` - The number of arguments expected by the assertion function.

Returns:

True if the arguments contain a comment, false otherwise.

### evalArguments

    <static> Boolean evalArguments(<Object> args, argsExpected)

Parameters:

`args` - The arguments array.

`nr` - The number of arguments to be expected

Returns:

True in case the number of arguments matches the expected amount, false otherwise.

### getComment

    <static> String getComment(<Array> args, argsExpected)

Cuts out the comment from the arguments array passed as argument and returns it. CAUTION: this actually modifies the arguments array!

Parameters:

`args` - The arguments array.

Returns:

The comment, if existing. Null otherwise.

### getStackTrace

    <static> String getStackTrace(<java.lang.StackTraceElement> trace)

Creates a stack trace and parses it for display.

Parameters:

`trace` - The trace to parse. If not given a stacktrace will be generated

Returns:

The parsed stack trace

### getTestFile

    <static> helma.File getTestFile(<String> fileName)

Returns the testfile with the given name

Parameters:

`fileName` - The name of the test file

Returns:

The test file

### getTestFiles

    <static> Array getTestFiles()

Returns an array containing the test files located in the directory.

Returns:

An array containing the names of all test files

### getTestsDirectory

    <static> helma.File getTestsDirectory()

Returns the directory containing the test files. The location of the directory is either defined by the application property "jala.testDir" or expected to be one level above the application directory (and named "tests")

Returns:

The directory containing the test files

### getValue

    <static> Object getValue(<Array> args, argsExpected, <Number> idx)

Returns the argument on the index position in the array passed as arguments. This method respects an optional comment at the beginning of the arguments array.

Parameters:

`args` - The arguments to retrieve the non-comment value from.

`idx` - The index position on which the value to retrieve is to be expected if no comment is existing.

Returns:

The non-comment value, or null.

### include

    <static> void include(<Object> scope, file)

Evaluates a javascript file in the global test scope. This method can be used to include generic testing code in test files. This method is available as global method "include" for all test methods

Parameters:

`scope` - The scope in which the file should be evaluated

`fileName` - The name of the file to include, including the path

### valueToString

    <static> String valueToString(val)

Helper method useable for displaying a value

Parameters:

`The` - value to render

Returns:

The value rendered as string

Jala Test

Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008