The goog.testing.TestCase Class

goog.testing.TestCase(opt_name)

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 {@link #autoDiscoverTests}

opt_name {string=}
The name of the test case, defaults to 'Untitled Test Case'.

The goog.testing.TestCase.Error Class

A class representing an error thrown by the test … more

.IS_IE {boolean}

Avoid a dependency on goog.userAgent and keep our own reference of whether the browser is IE.

.MAX_RUN_TIME {number}

The maximum amount of time that the test can run before we force it to be async. This prevents the test runner from blocking the browser and potentially hurting the Selenium test harness.

The goog.testing.TestCase.Order Enum

The order to run the auto-discovered tests. … more

The goog.testing.TestCase.Result Class

A class for representing test results. A bag of public properties. … more

The goog.testing.TestCase.Test Class

A class representing a single test function. … more

.add(test)

Adds a new test to the test case.

test {goog.testing.TestCase.Test}
The test to add.

.autoDiscoverTests()

Adds any functions defined in the global scope that are prefixed with "test" to the test case. Also overrides setUp, tearDown, setUpPage, tearDownPage and runTests if they are defined.

.currentTestName {?string}

TODO(user) replace this with prototype.currentTest. Name of the current test that is running, or null if none is running.

.cycleTests()

Cycles through the tests, breaking out using a setTimeout if the execution time has execeeded {@link #MAX_RUN_TIME}.

.execute()

Executes each of the tests.

.finalize()

Finalizes the test case, called when the tests have finished executing.

.getActuallyRunCount()

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.

.getCount()

Returns the number of tests contained in the test case.

returns {number}
The number of tests.

.getGlobals(opt_prefix)

Gets the object with all globals.

opt_prefix {string=}
An optional prefix. If specified, only get things under this prefix.
returns {Object}
An object with all globals starting with the prefix.

.getNumFilesLoaded()

Returns the number of script files that were loaded in order to run the test.

returns {number}
The number of script files.

.getReport(opt_verbose)

Returns a string detailing the results from the test.

opt_verbose {boolean=}
If true results will include data about all tests, not just what failed.
returns {string}
The results from the test.

.getRunTime()

Returns the amount of time it took for the test to run.

returns {number}
The run time, in milliseconds.

.initializeTestRunner(testCase)

Initializes the given test case with the global test runner 'G_testRunner'.

testCase {goog.testing.TestCase}
The test case to install.

.isInsideMultiTestRunner()

returns {boolean}
Whether the test case is running inside the multi test runner.

.isSuccess()

returns {boolean}
Whether the test was a success.

.log(val)

Logs an object to the console, if available.

val {*}
The value to log. Will be ToString'd.

.logError(name, opt_e)

name {string}
Failed test name.
opt_e {*=}
The exception object associated with the failure or a string.
returns {goog.testing.TestCase.Error}
Error object.

.next()

Returns the current test and increments the pointer.

returns {goog.testing.TestCase.Test?}
The current test case.

.order {string}

The order to run the auto-discovered tests in.

.reset()

Resets the test case pointer, so that next returns the first test.

.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.

.running {boolean}

Whether the test case is running.

.saveMessage(message)

Saves a message to the result set.

message {string}
The message to save.

.setCompletedCallback(fn)

Sets the callback function that should be executed when the tests have completed.

fn {Function}
The callback function.

.setTestRunner(tr)

Sets the test runner that is running this test case.

tr {goog.testing.TestRunner}
The test runner.

.setUp()

Gets called before every goog.testing.TestCase.Test is been executed. Can be overridden to add set up functionality to each test.

.setUpPage()

Gets called before any tests are executed. Can be overridden to set up the environment for the whole test case.

.shouldRunTests()

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.

.started {boolean}

Whether the test case has ever tried to execute.

.tearDown()

Gets called after every goog.testing.TestCase.Test has been executed. Can be overriden to add tear down functionality to each test.

.tearDownPage()

Gets called after all tests have been executed. Can be overridden to tear down the entire test case.