testing

Classes

goog.testing.AsyncTestCase
A test case that is capable of running tests the contain asynchronous logic.
goog.testing.ContinuationTestCase
Constructs a test case that supports tests with continuations. Test functions may issue "wait" commands that suspend the test temporarily and continue once the wait condition is met.
goog.testing.DeferredTestCase
A test case that can asynchronously wait on a Deferred object.
goog.testing.ExpectedFailures
Helper class for allowing some unit tests to fail, particularly designed to mark tests that should be fixed on a given browser.
var expectedFailures = new goog.testing.ExpectedFailures();

function tearDown() {
  expectedFailures.handleTearDown();
}

function testSomethingThatBreaksInWebKit() {
  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);

  try {
    ...
    assert(somethingThatFailsInWebKit);
    ...
  } catch (e) {
    expectedFailures.handleException(e);
  }
}
goog.testing.FunctionCall
Struct for a single function call.
goog.testing.LooseExpectationCollection
This class is an ordered collection of expectations for one method. Since the loose mock does most of its verification at the time of $verify, this class is necessary to manage the return/throw behavior when the mock is being called.
goog.testing.LooseMock
This is a mock that does not care about the order of method calls. As a result, it won't throw exceptions until verify() is called. The only exception is that if a method is called that has no expectations, then an exception will be thrown.
goog.testing.Mock
The base class for a mock object.
goog.testing.MockClassFactory
A factory used to create new mock class instances. It is able to generate both static and loose mocks. The MockClassFactory is a singleton since it tracks the classes that have been mocked internally.
goog.testing.MockClassRecord
A record that represents all the data associated with a mock replacement of a given class.
goog.testing.MockClock
Class for unit testing code that uses setTimeout and clearTimeout. NOTE: If you are using MockClock to test code that makes use of goog.fx.Animation, then you must either: 1. Install and dispose of the MockClock in setUpPage() and tearDownPage() respectively (rather than setUp()/tearDown()). or 2. Ensure that every test clears the animation queue by calling mockClock.tick(x) at the end of each test function (where `x` is large enough to complete all animations). Otherwise, if any animation is left pending at the time that MockClock.dispose() is called, that will permanently prevent any future animations from playing on the page.
goog.testing.MockControl
Controls a set of mocks. Controlled mocks are replayed, verified, and cleaned-up at the same time.
goog.testing.MockExpectation
This is a class that represents an expectation.
goog.testing.MockRandom
Class for unit testing code that uses Math.random.
goog.testing.MockRange
LooseMock of goog.dom.AbstractRange. Useful because the mock framework cannot simply create a mock out of an abstract class, and cannot create a mock out of classes that implements __iterator__ because it relies on the default behavior of iterating through all of an object's properties.
goog.testing.MockStorage
A JS storage instance, implementing the HMTL5 Storage interface. See http://www.w3.org/TR/webstorage/ for details.
goog.testing.MockUserAgent
Class for unit testing code that uses goog.userAgent.
goog.testing.MultiTestRunner
A component for running multiple tests within the browser.
goog.testing.ObjectPropertyString
Object to pass a property name as a string literal and its containing object when the JSCompiler is rewriting these names. This should only be used in test code.
goog.testing.PerformanceTable
A UI widget that runs performance tests and displays the results.
goog.testing.PerformanceTimer
Creates a performance timer that runs test functions a number of times to generate timing samples, and provides performance statistics (minimum, maximum, average, and standard deviation).
goog.testing.PropertyReplacer
Helper class for stubbing out variables and object properties for unit tests. This class can change the value of some variables before running the test cases, and to reset them in the tearDown phase. See googletest.StubOutForTesting as an analogy in Python: http://protobuf.googlecode.com/svn/trunk/python/stubout.py Example usage:
var stubs = new goog.testing.PropertyReplacer();

function setUp() {
  // Mock functions used in all test cases.
  stubs.set(Math, 'random', function() {
    return 4;  // Chosen by fair dice roll. Guaranteed to be random.
  });
}

function tearDown() {
  stubs.reset();
}

function testThreeDice() {
  // Mock a constant used only in this test case.
  stubs.set(goog.global, 'DICE_COUNT', 3);
  assertEquals(12, rollAllDice());
}
Constraints on altered objects:
  • DOM subclasses aren't supported.
  • The value of the objects' constructor property must either be equal to the real constructor or kept untouched.
goog.testing.PseudoRandom
Class for unit testing code that uses Math.random. Generates deterministic random numbers.
goog.testing.ShardingTestCase
A test case that runs tests in per-file shards.
goog.testing.StrictMock
This is a mock that verifies that methods are called in the order that they are specified during the recording phase. Since it verifies order, it follows 'fail fast' semantics. If it detects a deviation from the expectations, it will throw an exception and not wait for verify to be called.
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 #autoDiscoverLifecycle and #autoDiscoverTests
goog.testing.TestQueue
Generic queue for writing unit tests
goog.testing.TestRunner
Construct a test runner. NOTE(user): This is currently pretty weird, I'm essentially trying to create a wrapper that the Selenium test can hook into to query the state of the running test case, while making goog.testing.TestCase general.

Public Protected Private

Global Functions

goog.testing.FunctionMock(opt_functionNameopt_strictness) goog.testing.MockInterface
Class used to mock a function. Useful for mocking closures and anonymous callbacks etc. Creates a function object that extends goog.testing.Mock.
Arguments:
opt_functionName : string=
The optional name of the function to mock. Set to '[anonymous mocked function]' if not passed in.
opt_strictness : number=
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
Returns: goog.testing.MockInterface  The mocked function.
code »
goog.testing.GlobalFunctionMock(functionNameopt_strictness) !goog.testing.MockInterface
Mocks a global / top-level function. Creates a goog.testing.MethodMock in the global scope with the name specified by functionName.
Arguments:
functionName : string
The name of the function we're going to mock.
opt_strictness : number=
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
Returns: !goog.testing.MockInterface  The mocked global function.
code »
goog.testing.MethodMock(scopefunctionNameopt_strictness) !goog.testing.MockInterface
Mocks an existing function. Creates a goog.testing.FunctionMock and registers it in the given scope with the name specified by functionName.
Arguments:
scope : Object
The scope of the method to be mocked out.
functionName : string
The name of the function we're going to mock.
opt_strictness : number=
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
Returns: !goog.testing.MockInterface  The mocked method.
code »
goog.testing.createConstructorMock(scopeconstructorNameopt_strictness) !goog.testing.MockInterface
Convenience method for creating a mock for a constructor. Copies class members to the mock.

When mocking a constructor to return a mocked instance, remember to create the instance mock before mocking the constructor. If you mock the constructor first, then the mock framework will be unable to examine the prototype chain when creating the mock instance.

Arguments:
scope : Object
The scope of the constructor to be mocked out.
constructorName : string
The name of the constructor we're going to mock.
opt_strictness : number=
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
Returns: !goog.testing.MockInterface  The mocked constructor.
code »
goog.testing.createFunctionMock(opt_functionNameopt_strictness) goog.testing.MockInterface
Convenience method for creating a mock for a function.
Arguments:
opt_functionName : string=
The optional name of the function to mock set to '[anonymous mocked function]' if not passed in.
opt_strictness : number=
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
Returns: goog.testing.MockInterface  The mocked function.
code »
goog.testing.createGlobalFunctionMock(functionNameopt_strictness) goog.testing.MockInterface
Convenience method for creating a mocks for a global / top-level function.
Arguments:
functionName : string
The name of the function we're going to mock.
opt_strictness : number=
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
Returns: goog.testing.MockInterface  The mocked global function.
code »
goog.testing.createMethodMock(scopefunctionNameopt_strictness) !goog.testing.MockInterface
Convenience method for creating a mock for a method.
Arguments:
scope : Object
The scope of the method to be mocked out.
functionName : string
The name of the function we're going to mock.
opt_strictness : number=
One of goog.testing.Mock.LOOSE or goog.testing.Mock.STRICT. The default is STRICT.
Returns: !goog.testing.MockInterface  The mocked global function.
code »
goog.testing.recordConstructor(ctor) !Function
Same as goog.testing.recordFunction but the recorded function will have the same prototype and static fields as the original one. It can be used with constructors.
Arguments:
ctor : !Function
The function to wrap and record.
Returns: !Function  The wrapped function.
code »
goog.testing.recordFunction(opt_f) !Function
Wraps the function into another one which calls the inner function and records its calls. The recorded function will have 3 static methods: getCallCount, getCalls and getLastCall but won't inherit the original function's prototype and static fields.
Arguments:
opt_f : !Function=
The function to wrap and record. Defaults to goog.nullFunction.
Returns: !Function  The wrapped function.
code »

Global Properties

goog.testing.AsyncTestCaseAsyncTest :
No description.
Code »
goog.testing.AsyncTestCaseSyncTest :
No description.
Code »
goog.testing.AsyncTestCaseTest :
No description.
Code »
goog.testing.ContinuationTestCaseTest :
No description.
Code »
goog.testing.DeferredTestCaseTest :
No description.
Code »
goog.testing.ExpectedFailuresTest :
No description.
Code »
goog.testing.FunctionMockTest :
No description.
Code »
goog.testing.LooseMockTest :
No description.
Code »
goog.testing.MockClassFactoryTest :
No description.
Code »
goog.testing.MockClockTest :
No description.
Code »
goog.testing.MockControlTest :
No description.
Code »
goog.testing.MockRandomTest :
No description.
Code »
goog.testing.MockRangeTest :
No description.
Code »
goog.testing.MockStorageTest :
No description.
Code »
goog.testing.MockTest :
No description.
Code »
goog.testing.MockUserAgentTest :
No description.
Code »
goog.testing.PerformanceTimerTest :
No description.
Code »
goog.testing.PropertyReplacerTest :
No description.
Code »
goog.testing.PseudoRandomTest :
No description.
Code »
goog.testing.ShardingTestCaseTest :
No description.
Code »
goog.testing.StrictMockTest :
No description.
Code »
goog.testing.asserts :
No description.
Code »
goog.testing.assertsTest :
No description.
Code »
goog.testing.async :
No description.
Code »
goog.testing.benchmark :
No description.
Code »
goog.testing.dom :
No description.
Code »
goog.testing.domTest :
No description.
Code »
goog.testing.editor :
No description.
Code »
goog.testing.events :
No description.
Code »
goog.testing.eventsTest :
No description.
Code »
goog.testing.fs :
No description.
Code »
goog.testing.fsTest :
No description.
Code »
goog.testing.graphics :
No description.
Code »
goog.testing.i18n :
No description.
Code »
goog.testing.jsunit :
No description.
Code »
goog.testing.messaging :
No description.
Code »
goog.testing.mockmatchers :
No description.
Code »
goog.testing.mockmatchersTest :
No description.
Code »
goog.testing.net :
No description.
Code »
goog.testing.proto2 :
No description.
Code »
goog.testing.proto2Test :
No description.
Code »
goog.testing.recordFunctionTest :
No description.
Code »
goog.testing.singleton :
No description.
Code »
goog.testing.singletonTest :
No description.
Code »
goog.testing.stacktrace :
No description.
Code »
goog.testing.stacktraceTest :
No description.
Code »
goog.testing.storage :
No description.
Code »
goog.testing.style :
No description.
Code »
goog.testing.styleTest :
No description.
Code »
goog.testing.ui :
No description.
Code »
goog.testing.watchers :
No description.
Code »

Package testing

Package Reference