Class: CoreTest.Suite

A test Suite defines a group of reusable unit tests that can be added to a test plan at any time by calling the generate() method. Suites are most useful for defining groups of tests that validate compliance with a mixin. You can then generate customized versions of the test suite for different types of objects to ensure that both the mixin and the object implementing the mixin use the API properly.

Using a Suite

To use a Suite, call the generate() method on the suite inside on of your unit test files. This will generate new modules and tests in the suite and add them to your test plan.

Usually you will need to customize the suite to apply to a specific object. You can supply these customizations through an attribute hash passed to the generate() method. See the documentation on the specific test suite for information on the kind of customizations you may need to provide.


// generates the SC.ArrayTestSuite tests for a built-in array.
SC.ArrayTests.generate('Array', {
  newObject: function() { return []; }

Defining a Suite

To define a test suite, simply call the extend() method, passing any attributes you want to define on the suite along with this method. You can then add functions that will define the test suite with the define() method.

Functions you pass to define will have an instance of the test suite passed as their first parameter when invoked.


SC.ArrayTests = CoreTest.Suite.create("Verify SC.Array compliance", {

  // override to generate a new object that implements SC.Array
  newObject: function() { return null; }

SC.ArrayTests.define(function(T) {
  T.module("length tests");

  test("new length", function() {
    equals(T.object.get('length'), 0, 'array length');


Defined in: suite.js

SproutCore 1.0

Field Summary

Instance Methods

Field Detail


The base description string. This should accept two formatting options, a sub description and a detailed description. This is the description set when you call extend()


Definition functions. These are invoked in order when you generate a suite to add unit tests and modules to the test plan.

Instance Method Detail

create(attrs, attrs)

Call this method to define a new test suite. Pass one or more hashes of properties you want added to the new suite.

attrs Hash
one or more attribute hashes
subclass of suite.

Adds the passed function to the array of definitions that will be invoked when the suite is generated.

The passed function should expect to have the TestSuite instance passed as the first and only parameter. The function should actually define a module and tests, which will be added to the test suite.

func Function
definition function

Generates a module description by merging the based description, sub description and the passed description. This is usually used inside of a suite definition function.

str String
detailed description for this module
generated description

Default method to destroy a generated object instance after a test has completed. If you override newObject() you can also override this method to cleanup the object you just created.

Default method does nothing.

generate(desc, attrs)

Generate a new test suite instance, adding the suite definitions to the current test plan. Pass a description of the test suite as well as one or more attribute hashes to apply to the test plan.

The description you add will be prefixed in front of the 'desc' property on the test plan itself.

desc String
suite description
attrs Hash
one or more attribute hashes
suite instance

Generates a default module with the description you provide. This is a convenience function for use inside of a definition function. You could do the same thing by calling:

var T = this ;
module(T.desc(description), {
  setup: function() { T.setup(); },
  teardown: function() { T.teardown(); }
desc String
detailed description

Default method to create a new object instance. You will probably want to override this method when you generate() a suite with a function that can generate the type of object you want to test.

generated object

Default setup method for use with modules. This method will call the newObject() method and set its return value on the object property of the receiver.


Default teardown method for use with modules. This method will call the destroyObject() method, passing the current object property on the receiver. It will also clear the object property.

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)