Hemi JavaScript Framework
Hemi.app.module.test
Description
Test Modules are Modules decorated for unit testing. For example, the Application Component Tests includes several unit tests for vetting the Application Component class.
Class Index
static Hemi.app.module.test.service
version 3.1.9
Static implementation of the hemi.app.module.serviceImpl class.
Hemi.app.module.test.serviceImpl
version 3.1.9
The module service provides a convenience for modularizing and managing standard JavaScript as reusable components and tests.
Index
Object Index
- public TestModule: A TestModule encapsulates the imported JavaScript and an API for operating within the framework, and includes a testing harness.
- public TestResult: A TestResult represents the collected and specified metrics of a specific test invocation.
Method Index
- public NewTest: Creates a new TestModule object.
- public UnloadTest: Unloads the specified test module.
Objects
TestModule
A TestModule encapsulates the imported JavaScript and an API for operating within the framework, and includes a testing harness.
Properties
- TestMembers as Array<String>: Array of test names. Property is only available when module is loaded as a TestModule.
- Container as Node: A pointer to the XHTML Node for which the module was loaded.
- Component as XHTMLComponent: A pointer to the XHTMLComponent created for any Container, if a Container was used.
Methods
- void _AM(
oTest, sMessage)
Logs the specified message as an error and adds the message to the specified TestResult messages array.
- void Assert(
bCondition, sMessage)
Asserts a condition as being true. If false, an exception is raised with the specified message. Within a test case, the exception is caught and recorded against an internal test object for use in propogating the results.
- void ContinueTest*(
)
Used for cyclical testing and from callbacks while handling dependencies Used for asynchronous tests with asynchronous dependencies.
- void EndTest*(
bResult)
EndTest* completes the execution of the test. When a test explicitly returns false, the test result remains open until this method is explicitly invoked. This allows test suites to include asynchronous tests.
- String = getReport(
)
Returns a formatted text report of all test results.
- array = getTests(
)
Every test invocation generates a new TestResultObject and passes that object to the test. The test can set the status or message property on the result, and the result is stored in the test results array.
- Task = getTestTask(
)
Returns the task object used to correlate the test state across the suite.
- void HandleContinueTest*(
testResult)
HandleContinueTest* is called when ContinueTest* is invoked.
- void Initialize(
)
Invoked when the module is loaded.
- void log(
sMessage)
Sends a message in the ###.3 message block.
- void logAdvisory(
sMessage)
Sends a message in the ###.2 message block.
- void logDebug(
sMessage)
Sends a message in the ###.1 message block.
- void logError(
sMessage)
Sends a message in the #100.5 message block.
- void logFatal(
sMessage)
Sends a message in the ###.7 message block.
- void logWarning(
sMessage)
Sends a message in the ###.4 message block.
- void ResetSuite(
)
Resets the tasklist that correlates the tests. This will cause existing dependencies on these tests to be resolved, and the test suite will be assigned a new task id.
- void RunTest(
sTestName)
Executes the specified test.
- void RunTests(
)
Executes all discovered test cases. Test results are logged to the 621.#.#.# message space (refer to hemi.util.logger and hemi.message for more information). Method is only available when module is loaded as a TestModule.
- boolean = Test*(
testResult)
When a module is created as a test, any public function whose name begins with Test (e.g.: funtion TestThisScript(){}) is parsed as a managed unit test case.
TestResult
A TestResult represents the collected and specified metrics of a specific test invocation.
Properties
- name as String: The name of the test.
- start_time as Date: The time when the test began.
- stop_time as Date: The time when the test completed.
- status as int: The status of the result. 0 = created; 1 = prior to start, 2 = after run, 3 = before end, 4 = ended.
- error as boolean: Bit indicating a failure or exception occured.
- messages as Array<String>: A string array of messages.
- data as variant: General data property for storing data during the execution of the test.
Methods
NewTest
Creates a new TestModule object.
Syntax
oTestModule = NewTest(
sName, oContainer, fTestHandler, fSuiteHandler, sPath, sContent
)
Parameters
- sName as String : Name of the Test Module
- oContainer as XHTMLComponent (optional): XHTML Component acting as a container for the module.
- fTestHandler as function (optional): Function handler to be invoked when test status has changed.
- fSuiteHandler as function (optional): Function handler to be invoked when all tests have been completed.
- sPath as String (optional): Parent path to the test module.
- sContent as String (optional): Content of the test module.
Returns
oTestModule as TestModule: A new TestModule object.
UnloadTest
Unloads the specified test module.
Syntax
bRemoved = UnloadTest(
sTest
)
Parameters
- sTest as String : Name of the Test Module
Returns
bRemoved as boolean: Bit indicating whether the test was removed.
[ Hemi JavaScript Framework - Stephen W. Cote, 2002 - 2011. ]