Unit-Test Result Macro Reference

The SenTestingKit framework defines a set of test case result macros that report test case results to the framework. When a test fails, the framework sends a test-failure message, which Xcode displays in the log and issue navigators.

The following sections describe the test result macros you can use in your test case methods. These macros are declared in SenTestCase.h.

Unconditional Failure

STFail

Fails the test case.

STFail(failure_description, ...)

Parameters

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Equality Tests

STAssertEqualObjects

Fails the test case when two objects are different.

STAssertEqualObjects(object_1, object_2, failure_description, ...)

Parameters

object_1

  • An object.

object_2

  • An object.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Detail

The test fails when [object_1 isEqualTo:object_2] is false.

STAssertEquals

Fails the test case when two values are different.

STAssertEquals(value_1, value_2, failure_description, ...)

Parameters

value_1

  • A scalar, structure, or union.

value_2

  • A scalar, structure, or union.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Detail

The test fails when value_1 is not equal to value_2.

STAssertEqualsWithAccuracy

Fails the test case when the difference between two values is greater than a given value.

STAssertEqualsWithAccuracy(value_1, value_2, accuracy, failure_description, ...)

Parameters

value_1

  • An integer or a floating-point value.

value_2

  • An integer or a floating-point value.

accuracy

  • An integer or a floating-point value.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Detail

The test fails when the difference between value_1 and value_2 is greater than accuracy.

Nil Tests

STAssertNil

Fails the test case when a given expression is not nil.

STAssertNil(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

STAssertNotNil

Fails the test case when a given expression is nil.

STAssertNotNil(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Boolean Tests

STAssertTrue

Fails the test case when a given expression is false.

STAssertTrue(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

STAssertFalse

Fails the test case when a given expression is true.

STAssertFalse(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Exception Tests

STAssertThrows

Fails the test case when an expression doesn’t raise an exception.

STAssertThrows(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

STAssertThrowsSpecific

Fails the test case when an expression doesn’t raise an exception of a particular class.

STAssertThrowsSpecific(expression, exception_class, failure_description, ...)

Parameters

expression

  • Expression to test.

exception_class

  • An exception class.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Detail

The test fails when expression doesn’t raise an exception of the class exception_class.

STAssertThrowsSpecificNamed

Fails the test case when an expression doesn’t raise an exception of a particular class with a given name.

STAssertThrowsSpecificNamed(expression, exception_class, exception_name, failure_description, ...)

Parameters

expression

  • Expression to test.

exception_class

  • An exception class.

exception_name

  • A string with the name of an exception.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Detail

The test fails when expression doesn’t raise an exception of the class exception_class with the name exception_name.

STAssertNoThrow

Fails the test case when an expression raises an exception.

STAssertNoThrow(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

STAssertNoThrowSpecific

Fails the test case when an expression raises an exception of a particular class.

STAssertNoThrowSpecific(expression, exception_class, failure_description, ...)

Parameters

expression

  • Expression to test.

exception_class

  • An exception class.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Detail

The test fails when expression raises an exception of the class exception_class.

STAssertNoThrowSpecificNamed

Fails the test case when an expression doesn’t raise an exception of a particular class with a given name.

STAssertNoThrowSpecificNamed(expression, exception_class, exception_name, failure_description, ...)

Parameters

expression

  • Expression to test.

exception_class

  • An exception class.

exception_name

  • A string with the name of an exception.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

Detail

The test fails when the expression raises an exception of the class exception_class with the name exception_name.

STAssertTrueNoThrow

Fails the test case when an expression is false or raises an exception.

STAssertTrueNoThrow(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.

STAssertFalseNoThrow

Fails the test case when an expression is true or raises an exception.

STAssertFalseNoThrow(expression, failure_description, ...)

Parameters

expression

  • Expression to test.

failure_description

  • Format string specifying error message. Can be nil.

...

  • (Optional) A comma-separated list of arguments to substitute into failure_description.