The goog.testing Namespace

The goog.testing.AsyncTestCase Class

A test case that is capable of running tests the contain asynchronous logic. … more

The goog.testing.ContinuationTestCase Class

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

The goog.testing.DeferredTestCase Class

A test case that can asynchronously wait on a Deferred object. … more

The goog.testing.ExpectedFailures Class

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);
   }
 }
 
… more

The goog.testing.FunctionCall Class

Struct for a single function call. … more

.FunctionMock(opt_functionName, opt_strictness)

Class used to mock a function. Useful for mocking closures and anonymous callbacks etc. Creates a function object that extends goog.testing.Mock.

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.
@suppress
{missingProperties} Mocks do not fit in the type system well.

.GlobalFunctionMock(functionName, opt_strictness)

Mocks a global / top-level function. Creates a goog.testing.MethodMock in the global scope with the name specified by functionName.

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.

The goog.testing.JsUnitException Class

… more

The goog.testing.LooseExpectationCollection Class

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

The goog.testing.LooseMock Class

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

The goog.testing.MethodMock Namespace

Mocks an existing function. Creates a goog.testing.FunctionMock and registers it in the given scope with the name specified by functionName. … more

The goog.testing.Mock Class

The base class for a mock object. … more

The goog.testing.MockClassFactory Class

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

The goog.testing.MockClassRecord Class

A record that represents all the data associated with a mock replacement of a given class. … more

The goog.testing.MockClock Class

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

The goog.testing.MockControl Class

Controls a set of mocks. Controlled mocks are replayed, verified, and cleaned-up at the same time. … more

The goog.testing.MockExpectation Class

This is a class that represents an expectation. … more

The goog.testing.MockInterface Interface

… more

The goog.testing.MockRandom Class

Class for unit testing code that uses Math.random. … more

The goog.testing.MockRange Class

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

The goog.testing.MockStorage Class

A JS storage instance, implementing the HMTL5 Storage interface. See http://www.w3.org/TR/webstorage/ for details. … more

The goog.testing.MockUserAgent Class

Class for unit testing code that uses goog.userAgent. … more

The goog.testing.MultiTestRunner Class

A component for running multiple tests within the browser. … more

The goog.testing.ObjectPropertyString Class

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

The goog.testing.PerformanceTable Class

A UI widget that runs performance tests and displays the results. … more

The goog.testing.PerformanceTimer Class

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). … more

The goog.testing.PropertyReplacer Class

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: … more

The goog.testing.PseudoRandom Class

Class for unit testing code that uses Math.random. Generates deterministic random numbers. … more

The goog.testing.ShardingTestCase Class

A test case that runs tests in per-file shards. … more

The goog.testing.StrictMock Class

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

The goog.testing.TestCase Class

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} … more

The goog.testing.TestQueue Class

Generic queue for writing unit tests … more

The goog.testing.TestRunner Class

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

The goog.testing.asserts Namespace

… more

The goog.testing.async Namespace

… more

The goog.testing.benchmark Namespace

… more

.createConstructorMock(scope, constructorName, opt_strictness)

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.

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.

.createFunctionMock(opt_functionName, opt_strictness)

Convenience method for creating a mock for a function.

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.

.createGlobalFunctionMock(functionName, opt_strictness)

Convenience method for creating a mocks for a global / top-level function.

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.

.createMethodMock(scope, functionName, opt_strictness)

Convenience method for creating a mock for a method.

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.

The goog.testing.dom Namespace

… more

The goog.testing.editor Namespace

… more

The goog.testing.events Namespace

… more

The goog.testing.fs Namespace

… more

The goog.testing.graphics Namespace

… more

The goog.testing.jsunit Namespace

… more

The goog.testing.messaging Namespace

… more

The goog.testing.mockmatchers Namespace

… more

The goog.testing.net Namespace

… more

.recordConstructor(ctor)

Same as {@link 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.

ctor {!Function}
The function to wrap and record.
returns {!Function}
The wrapped function.

.recordFunction(opt_f)

Wraps the function into another one which calls the inner function and records its calls. The recorded function will have 3 static methods: {@code getCallCount}, {@code getCalls} and {@code getLastCall} but won't inherit the original function's prototype and static fields.

opt_f {!Function=}
The function to wrap and record. Defaults to {@link goog.nullFunction}.
returns {!Function}
The wrapped function.

The goog.testing.singleton Namespace

… more

The goog.testing.stacktrace Namespace

… more

The goog.testing.storage Namespace

… more

The goog.testing.style Namespace

… more

The goog.testing.ui Namespace

… more