iOS Reference Library Apple Developer
Search

Unit-Test Result Macro Reference

The SenTestingKit framework defines a set of test-case result macros that allow you to report the test-case results to the framework. When a test fails, the framework emits a test-failure message, which Xcode displays in text-editor, Build Results, or console windows, depending on the type of unit tests being performed.

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

Important: When the expressions your test cases evaluate throw exceptions, they produce unknown errors. To test whether your code raises exceptions, create test cases that explicitly check for the presence or absence or exceptions; see ‚ÄúException Tests.‚Äù

Unconditional Failure

STFail

Fails the test case.

STFail(failure_description, ...)

Parameters

failure_description

...

Equality Tests

STAssertEqualObjects

Fails the test case when two objects are different.

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

Parameters

object_1

object_2

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

value_2

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

value_2

accuracy

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

failure_description

...

STAssertNotNil

Fails the test case when a given expression is nil.

STAssertNotNil(expression, failure_description, ...)

Parameters

expression

failure_description

...

Boolean Tests

STAssertTrue

Fails the test case when a given expression is false.

STAssertTrue(expression, failure_description, ...)

Parameters

expression

failure_description

...

STAssertFalse

Fails the test case when a given expression is true.

STAssertFalse(expression, failure_description, ...)

Parameters

expression

failure_description

...

Exception Tests

STAssertThrows

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

STAssertThrows(expression, failure_description, ...)

Parameters

expression

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

exception_class

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

exception_class

exception_name

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

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

exception_class

failure_description

...

Detail

The test fails 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

exception_class

exception_name

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

failure_description

...

STAssertFalseNoThrow

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

STAssertFalseNoThrow(expression, failure_description, ...)

Parameters

expression

failure_description

...




Last updated: 2010-07-02

Did this document help you? Yes It's good, but... Not helpful...