Class goog.testing.TestCase
code »A class representing a JsUnit test case. A TestCase is made up of a number
of test functions which can be run. Individual test cases can override the
following functions to set up their test environment:
- runTests - completely override the test's runner
- setUpPage - called before any of the test functions are run
- tearDownPage - called after all tests are finished
- setUp - called before each of the test functions
- tearDown - called after each of the test functions
- shouldRunTests - called before a test run, all tests are skipped if it
returns false. Can be used to disable tests on browsers
where they aren't expected to pass.
Use #autoDiscoverLifecycle
and #autoDiscoverTests
Constructor
Parameters |
---|
|
Classes
|
Enumerations
|
Instance Methods
Adds a new test to the test case.
Parameters |
---|
|
code »addNewTest ( name, ref, opt_scope )Creates and adds a new test.
Convenience function to make syntax less awkward when not using automatic
test discovery.
Adds any functions defined in the global scope that correspond to
lifecycle events for the test case. Overrides setUp, tearDown, setUpPage,
tearDownPage and runTests if they are defined.
Adds any functions defined in the global scope that are prefixed with "test"
to the test case.
code »clearTimeout ( id )Clears a timeout created by this.timeout()
.
this.timeout()
.Parameters |
---|
|
Counts the number of files that were loaded for dependencies that are
required to run the test.
Returns |
---|
|
code »createTestFromAutoDiscoveredFunction ( name, ref ) ⇒ !goog.testing.TestCase.Test
Creates a goog.testing.TestCase.Test
from an auto-discovered
function.
!goog.testing.TestCase.Test
goog.testing.TestCase.Test
from an auto-discovered
function.Parameters |
---|
|
Returns |
|
code »cycleTests ( )Cycles through the tests, breaking out using a setTimeout if the execution
time has execeeded #maxRunTime
.
#maxRunTime
.Handles a test that failed.
Parameters |
---|
|
Handles a test that passed.
Parameters |
---|
|
Returns the number of tests actually run in the test case, i.e. subtracting
any which are skipped.
Returns |
---|
|
Returns |
---|
|
code »getBatchTime ( ) ⇒ number
number
Returns |
---|
|
code »getGlobals ( opt_prefix ) ⇒ !Array
Gets list of objects that potentially contain test cases. For IE 8 and below,
this is the global "this" (for properties set directly on the global this or
window) and the RuntimeObject (for global variables and functions). For all
other browsers, the array simply contains the global this.
!Array
Parameters |
---|
|
Returns |
|
Returns the number of script files that were loaded in order to run the test.
Returns |
---|
|
code »getRunTime ( ) ⇒ number
Returns the amount of time it took for the test to run.
number
Returns |
---|
|
code »getTestResults ( ) ⇒ !Object.<string>
Returns the test results object: a map from test names to a list of test
failures (if any exist).
!Object.<string>
Returns |
---|
|
Gets the tests.
Returns |
---|
|
code »getTimeStamp_ ( ) ⇒ string
Returns the current time.
string
Returns |
---|
|
Returns |
---|
|
code »logError ( name, opt_e ) ⇒ !goog.testing.TestCase.Error
!goog.testing.TestCase.Error
Parameters |
---|
|
Returns |
|
code »maybeFailTestEarly ( testCase ) ⇒ boolean
Checks to see if the test should be marked as failed before it is run.
If there was an error in setUpPage, we treat that as a failure for all tests
and mark them all as having failed.
boolean
Parameters |
---|
|
Returns |
|
Returns the current test and increments the pointer.
Returns |
---|
|
code »orderTests_ ( tests )Reorders the tests depending on the order
field.
order
field.Parameters |
---|
|
code »saveMessage ( message )Saves a message to the result set.
Parameters |
---|
|
code »setBatchTime ( batchTime )
Parameters |
---|
|
code »setCompletedCallback ( fn )Sets the callback function that should be executed when the tests have
completed.
Parameters |
---|
|
Sets the tests.
Parameters |
---|
|
code »shouldRunTests ( ) ⇒ boolean
Can be overridden in test classes to indicate whether the tests in a case
should be run in that particular situation. For example, this could be used
to stop tests running in a particular browser, where browser support for
the class under test was absent.
boolean
Returns |
---|
|
Gets called after all tests have been executed. Can be overridden to tear
down the entire test case.
Instance Properties
Time since the last batch of tests was started, if batchTime exceeds
#maxRunTime
a timeout will be used to stop the tests blocking the
browser and a new batch will be started.
#maxRunTime
a timeout will be used to stop the tests blocking the
browser and a new batch will be started.Pointer to the current test.
Exception object that was detected before a test runs.
Optional callback that will be executed when the test has finalized.
Object used to encapsulate the test results.
Timestamp for when the test was started.
Set of test names and/or indices to execute, or null if all tests should
be executed.
Indices are included to allow automation tools to run a subset of the
tests without knowing the exact contents of the test file.
Indices should only be used with SORTED ordering.
Example valid values:
- [testName]
- [testName1, testName2]
- [2] - will run the 3rd test in the order specified
- [1,3,5]
- [testName1, testName2, 3, 5] - will work
Static Functions
code »goog.testing.TestCase.getGlobals ( opt_prefix ) ⇒ !Array
Gets list of objects that potentially contain test cases. For IE 8 and below,
this is the global "this" (for properties set directly on the global this or
window) and the RuntimeObject (for global variables and functions). For all
other browsers, the array simply contains the global this.
!Array
Parameters |
---|
|
Returns |
|
code »goog.testing.TestCase.initializeTestRunner ( testCase )Initializes the given test case with the global test runner 'G_testRunner'.
Parameters |
---|
|
Save a reference to window.clearTimeout
, so any code that overrides
the default behavior (e.g. MockClock) doesn't affect our runner.
window.clearTimeout
, so any code that overrides
the default behavior (e.g. MockClock) doesn't affect our runner.code »goog.testing.TestCase.protectedSetTimeout_ ( ) ⇒ number
Save a reference to window.setTimeout
, so any code that overrides the
default behavior (the MockClock, for example) doesn't affect our runner.
number
window.setTimeout
, so any code that overrides the
default behavior (the MockClock, for example) doesn't affect our runner.