testing.DeferredTestCase Extends goog.testing.AsyncTestCase
A test case that can asynchronously wait on a Deferred object.

Inheritance

Constructor

goog.testing.DeferredTestCase(opt_name)

Parameters

opt_name : string=
A descriptive name for the test case.

Instance Methods

Public Protected Private
addWaitForAsync(msgd)
Adds a callback to update the wait message of this async test case. Using this method generously also helps to document the test flow.
Arguments:
msg : string
The update wait status message.
d : goog.async.Deferred
The deferred object to add the waitForAsync callback to.
code »
onError(err)
Handler for when the test produces an error.
Arguments:
err : Error | string
The error object.
code »
onSuccess()
Handler for when the test succeeds.
code »
waitForDeferred(aopt_b)
Wires up given Deferred object to the test case, then starts the goog.async.Deferred object's callback.
Arguments:
a : !string | goog.async.Deferred
The wait status message or the deferred object to wait for.
opt_b : goog.async.Deferred=
The deferred object to wait for.
code »
callTopOfStackFunc_(func) !goog.testing.AsyncTestCase.TopStackFuncResult_
Calls the given function, redirecting any exceptions to doAsyncError.
Arguments:
func : Function
The function to call.
Returns: !goog.testing.AsyncTestCase.TopStackFuncResult_  Returns a TopStackFuncResult_.
code »
continueTesting()
Continue with the next step in the test cycle.
code »
cycleTests()
Starts the tests.
code »
dbgLog_(message)
Logs the given debug message to the console (when enabled).
Arguments:
message : string
The message to log.
code »
doAsyncError(opt_e)
Handles an exception thrown by a test.
Arguments:
opt_e : *=
The exception object associated with the failure or a string.
code »
doAsyncErrorTearDown_()
Calls the tearDown function, catching any errors, and then moves on to the next step in the testing cycle.
code »
doExecute_()
Step 3: Call test.execute().
code »
doIteration_()
Step 1: Move to the next test.
code »
doNext_()
Step 5: Call doSuccess()
code »
doSetUpPage_()
Sets up the test page and then waits untill the test case has been marked as ready before executing the tests.
code »
doSetUp_()
Step 2: Call setUp().
code »
doTearDown_()
Step 4: Call tearDown().
code »
doTopOfStackAsyncError_(opt_e)
Wraps doAsyncError() for when we are sure that the test runner has no user code above it in the stack.
Arguments:
opt_e : string | Error=
The exception object associated with the failure or a string.
code »
enableDebugLogging()
Enables verbose logging of what is happening inside of the AsyncTestCase.
code »
endCurrentStep_()
Ends the current test step and queues the next test step to run.
code »
finalize()
Finalizes the test case, called when the tests have finished executing.
code »
getCurrentStepName() !string
The current step name.
Returns: !string  Step name.
code »
hookAssert_()
Replaces the asserts.js assert_() and fail() functions with a wrappers to catch the exceptions.
code »
hookOnError_()
Sets a window.onerror handler for catching exceptions that happen in async callbacks. Note that as of Safari 3.1, Safari does not support this.
code »
pump_(opt_doFirst)
Calls the next callback when the isReady_ flag is true.
Arguments:
opt_doFirst : Function=
A function to call before pumping.
code »
runTests()
Sets up the test page and then waits until the test case has been marked as ready before executing the tests.
code »
setNextStep_(funcname)
Sets the next function to call in our sequence of async callbacks.
Arguments:
func : Function
The function that executes the next step.
name : string
A description of the next step.
code »
signal()
Signals once to continue with the test. If this is the last signal that the test was waiting on, call continueTesting.
code »
startTimeoutTimer_()
Enables the timeout timer. This timer fires unless continueTesting is called.
code »
stopTimeoutTimer_()
Disables the timeout timer.
code »
unhookAll_()
Unhooks window.onerror and _assert.
code »
waitForAsync(opt_name)
Informs the testcase not to continue to the next step in the test cycle until continueTesting is called.
Arguments:
opt_name : string=
A description of what we are waiting for.
code »
waitForSignals(timesopt_name)
Informs the testcase not to continue to the next step in the test cycle until signal is called the specified number of times. Within a test, this function behaves additively if called multiple times; the number of signals to wait for will be the sum of all expected number of signals this function was called with.
Arguments:
times : number
The number of signals to receive before continuing testing.
opt_name : string=
A description of what we are waiting for.
code »
add(test)
Adds a new test to the test case.
Arguments:
test : goog.testing.TestCase.Test
The test to add.
code »
addNewTest(namerefopt_scope)
Creates and adds a new test. Convenience function to make syntax less awkward when not using automatic test discovery.
Arguments:
name : string
The test name.
ref : !Function
Reference to the test function.
opt_scope : !Object=
Optional scope that the test function should be called in.
code »
autoDiscoverLifecycle()
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.
code »
autoDiscoverTests()
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().
Arguments:
id : number
A timeout id.
code »
countNumFilesLoaded_() number
Counts the number of files that were loaded for dependencies that are required to run the test.
Returns: number  The number of files loaded.
code »
createTestFromAutoDiscoveredFunction(nameref) !goog.testing.TestCase.Test
Creates a goog.testing.TestCase.Test from an auto-discovered function.
Arguments:
name : string
The name of the function.
ref : function() : void
The auto-discovered function.
Returns: !goog.testing.TestCase.Test  The newly created test.
code »
cycleTests()
Cycles through the tests, breaking out using a setTimeout if the execution time has execeeded #maxRunTime.
code »
doError(testopt_e)
Handles a test that failed.
Arguments:
test : goog.testing.TestCase.Test
The test that failed.
opt_e : *=
The exception object associated with the failure or a string.
code »
doSuccess(test)
Handles a test that passed.
Arguments:
test : goog.testing.TestCase.Test
The test that passed.
code »
execute()
Executes each of the tests.
code »
finalize()
Finalizes the test case, called when the tests have finished executing.
code »
getActuallyRunCount() number
Returns the number of tests actually run in the test case, i.e. subtracting any which are skipped.
Returns: number  The number of un-ignored tests.
code »
getAutoDiscoveryPrefix() string
No description.
Returns: string  The function name prefix used to auto-discover tests.
code »
getBatchTime() number
No description.
Returns: number  Time since the last batch of tests was started.
code »
getCount() number
Returns the number of tests contained in the test case.
Returns: number  The number of tests.
code »
getGlobals(opt_prefix) Object
Gets the object with all globals.
Arguments:
opt_prefix : string=
An optional prefix. If specified, only get things under this prefix. Note that the prefix is only honored in IE, since it supports the RuntimeObject: http://msdn.microsoft.com/en-us/library/ff521039%28VS.85%29.aspx TODO: Fix this method to honor the prefix in all browsers.
Returns: Object  An object with all globals starting with the prefix.
code »
getName() string
No description.
Returns: string  The name of the test.
code »
getNumFilesLoaded() number
Returns the number of script files that were loaded in order to run the test.
Returns: number  The number of script files.
code »
getReport(opt_verbose) string
Returns a string detailing the results from the test.
Arguments:
opt_verbose : boolean=
If true results will include data about all tests, not just what failed.
Returns: string  The results from the test.
code »
getRunTime() number
Returns the amount of time it took for the test to run.
Returns: number  The run time, in milliseconds.
code »
getTestResults() !Object.<string, !Array.<string>>
Returns the test results object: a map from test names to a list of test failures (if any exist).
Returns: !Object.<string, !Array.<string>>  Tests results object.
code »
getTests() !Array.<goog.testing.TestCase.Test>
Gets the tests.
Returns: !Array.<goog.testing.TestCase.Test>  The test array.
code »
getTimeStamp_() string
Returns the current time.
Returns: string  HH:MM:SS.
code »
isInsideMultiTestRunner() boolean
No description.
Returns: boolean  Whether the test case is running inside the multi test runner.
code »
isSuccess() boolean
No description.
Returns: boolean  Whether the test was a success.
code »
log(val)
Logs an object to the console, if available.
Arguments:
val : *
The value to log. Will be ToString'd.
code »
logError(nameopt_e) !goog.testing.TestCase.Error
No description.
Arguments:
name : string
Failed test name.
opt_e : *=
The exception object associated with the failure or a string.
Returns: !goog.testing.TestCase.Error  Error object.
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.
Arguments:
testCase : goog.testing.TestCase.Test
The current test case.
Returns: boolean  Whether the test was marked as failed.
code »
Returns the current test and increments the pointer.
Returns: goog.testing.TestCase.Test  The current test case.
code »
now() number
No description.
Returns: number  The current time in milliseconds, don't use goog.now as some tests override it.
code »
orderTests_(tests)
Reorders the tests depending on the order field.
Arguments:
tests : Array.<goog.testing.TestCase.Test>
An array of tests to reorder.
code »
pad_(number) string
Pads a number to make it have a leading zero if it's less than 10.
Arguments:
number : number
The number to pad.
Returns: string  The resulting string.
code »
reset()
Resets the test case pointer, so that next returns the first test.
code »
runTests()
Executes each of the tests. Overridable by the individual test case. This allows test cases to defer when the test is actually started. If overridden, finalize must be called by the test to indicate it has finished.
code »
saveMessage(message)
Saves a message to the result set.
Arguments:
message : string
The message to save.
code »
setBatchTime(batchTime)
No description.
Arguments:
batchTime : number
Time since the last batch of tests was started.
code »
setCompletedCallback(fn)
Sets the callback function that should be executed when the tests have completed.
Arguments:
fn : Function
The callback function.
code »
setTests(tests)
Sets the tests.
Arguments:
tests : !Array.<goog.testing.TestCase.Test>
A new test array.
code »
setUp()
Gets called before every goog.testing.TestCase.Test is been executed. Can be overridden to add set up functionality to each test.
code »
setUpPage()
Gets called before any tests are executed. Can be overridden to set up the environment for the whole test case.
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.
Returns: boolean  Whether any of the tests in the case should be run.
code »
tearDown()
Gets called after every goog.testing.TestCase.Test has been executed. Can be overriden to add tear down functionality to each test.
code »
tearDownPage()
Gets called after all tests have been executed. Can be overridden to tear down the entire test case.
code »
timeout(fntime) number
Calls a function after a delay, using the protected timeout.
Arguments:
fn : Function
The function to call.
time : number
Delay in milliseconds.
Returns: number  The timeout id.
code »
trimPath_(path) string
Trims a path to be only that after google3.
Arguments:
path : string
The path to trim.
Returns: string  The resulting string.
code »

Instance Properties

constructor :
No description.
Code »
The currently active test.
Code »
cleanedUp_ :
Marks if the cleanUp() function has been called for the currently running test.
Code »
constructor :
No description.
Code »
curStepFunc_ :
The stage of the test we are currently on.
Code »
curStepName_ :
The name of the stage of the test we are currently on.
Code »
enableDebugLogs_ :
Turn on extra logging to help debug failing async. tests.
Code »
expectedSignalCount_ :
Number of signals to wait for before continuing testing when waitForSignals is used.
Code »
inException_ :
A flag to prevent recursive exception handling.
Code »
isReady_ :
Flag used to determine if we can move to the next step in the testing loop.
Code »
nextStepFunc :
The stage of the test we should run next.
Code »
nextStepName_ :
The name of the stage of the test we should run next.
Code »
numControlExceptionsExpected_ :
The number of times we have thrown a ControlBreakingException so that we know not to complain in our window.onerror handler. In Webkit, window.onerror is not supported, and so this counter will keep going up but we won't care about it.
Code »
origAssert_ :
No description.
Code »
origFail_ :
No description.
Code »
origOnError_ :
A reference to the original window.onerror function.
Code »
receivedSignalCount_ :
Number of signals received.
Code »
returnWillPump_ :
Flag that tells us if there is a function in the call stack that will make a call to pump_().
Code »
stepTimeout :
How long to wait for a single step of a test to complete in milliseconds. A step starts when a call to waitForAsync() is made.
Code »
timeToSleepAfterFailure :
How long to wait after a failed test before moving onto the next one. The purpose of this is to allow any pending async callbacks from the failing test to finish up and not cause the next test to fail.
Code »
timeoutHandle_ :
The handle to the current setTimeout timer.
Code »
batchTime_ :
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.
Code »
currentTestPointer_ :
Pointer to the current test.
Code »
exceptionBeforeTest :
Exception object that was detected before a test runs.
Code »
name_ :
A name for the test case.
Code »
onCompleteCallback_ :
Optional callback that will be executed when the test has finalized.
Code »
order :
The order to run the auto-discovered tests in.
Code »
Object used to encapsulate the test results.
Code »
running :
Whether the test case is running.
Code »
startTime_ :
Timestamp for when the test was started.
Code »
started :
Whether the test case has ever tried to execute.
Code »
testsToRun_ :
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
    Code »
    tests_ :
    Array of test functions that can be executed.
    Code »

    Static Methods

    goog.testing.DeferredTestCase.createAndInstall(opt_name) !goog.testing.DeferredTestCase
    Preferred way of creating a DeferredTestCase. Creates one and initializes it with the G_testRunner.
    Arguments:
    opt_name : string=
    A descriptive name for the test case.
    Returns: !goog.testing.DeferredTestCase  The created DeferredTestCase.
    code »

    Static Properties

    goog.testing.DeferredTestCase.superClass_ :
    No description.
    Code »

    Package testing

    Package Reference