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.”
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
.
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.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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 expression
raises an exception of the class exception_class
.
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
.
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
.
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
.
Last updated: 2010-07-02