Home

# Class goog.testing.TestCase

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}

Instance Method Summary
| `add(?goog.testing.TestCase.Test test)` Adds a new test to the test case.
| `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.
| `countNumFilesLoaded_() ⇒ number` Counts the number of files that were loaded for dependencies that are required to run the test.
| `createTestFromAutoDiscoveredFunction(string name, function (): undefined ref) ⇒ ?goog.testing.TestCase.Test` Creates a {@code goog.testing.TestCase.Test} from an auto-discovered function.
| `cycleTests()` Cycles through the tests, breaking out using a setTimeout if the execution time has execeeded {@link #MAX_RUN_TIME}.
| `doError(?goog.testing.TestCase.Test test, <Any Type> opt_e)` Handles a test that failed.
| `doSuccess(?goog.testing.TestCase.Test test)` Handles a test that passed.
| `execute()` Executes each of the tests.
| `finalize()` Finalizes the test case, called when the tests have finished executing.
| `getAutoDiscoveryPrefix() ⇒ string`
| `getBatchTime() ⇒ number`
| `getCount() ⇒ number` Returns the number of tests contained in the test case.
| `getGlobals(string= opt_prefix) ⇒ ?Object` Gets the object with all globals.
| `getNumFilesLoaded() ⇒ number` Returns the number of script files that were loaded in order to run the test.
| `getReport(boolean= opt_verbose) ⇒ string` Returns a string detailing the results from the test.
| `getRunTime() ⇒ number` Returns the amount of time it took for the test to run.
| `getTests() ⇒ ?Array` Gets the tests.
| `getTimeStamp_() ⇒ string` Returns the current time.
| `isInsideMultiTestRunner() ⇒ boolean`
| `isSuccess() ⇒ boolean`
| `log(<Any Type> val)` Logs an object to the console, if available.
| `logError(string name, <Any Type> opt_e) ⇒ ?goog.testing.TestCase.Error`
| `next() ⇒ ?goog.testing.TestCase.Test` Returns the current test and increments the pointer.
| `now() ⇒ number`
| `orderTests_(?Array tests)` Reorders the tests depending on the {@code order} field.
| `pad_(number number) ⇒ string` Pads a number to make it have a leading zero if it's less than 10.
| `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.
| `saveMessage(string message)` Saves a message to the result set.
| `setBatchTime(number batchTime)`
| `setCompletedCallback(?Function fn)` Sets the callback function that should be executed when the tests have completed.
| `setTestRunner(?goog.testing.TestRunner tr)` Sets the test runner that is running this test case.
| `setTests(?Array tests)` Sets the tests.
| `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() ⇒ 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.
| `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.
| `timeout(?Function fn, number time) ⇒ number` Calls a function after a delay, using the protected timeout.
| `trimPath_(string path) ⇒ string` Trims a path to be only that after google3.

Static Method Summary
| `getGlobals(string= opt_prefix) ⇒ ?Object` Gets the object with all globals.
| `initializeTestRunner(?goog.testing.TestCase testCase)` Initializes the given test case with the global test runner 'G_testRunner'.