IOS unit test

Source: Internet
Author: User

From: http://www.devdiv.com/forum.php? MoD = viewthread & tid = 124254.

1. Unconditional failure)


Stfail
Failed test case

Stfail (failure_description ,...)
Parameters
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).



2.Equality Test)

Stassertequalobjects

Stassertequalobjects

Test failed when two objects are different
Stassertequalobjects (object_1, object_2, failure_description ,...)
Parameters
Object_1
An object
Object_2
An object

Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

NOTE: If [object_1 isdue to: object_2] is false, the test fails.

Stassertequals

The test fails when the two values are different.
Stassertequals (value_1, value_2, failure_description ,...)

Parameters
Value_1
A value, struct, or consortium.
Value_2
A value, struct, or consortium.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Note: The test fails if value_1 is not value_2.

Stassertequalswithaccuracy

If the difference between the two values is greater than the given value, the test fails.
Stassertequalswithaccuracy (value_1, value_2, accuracy, failure_description ,...)

Parameters
Value_1
An integer or floating point value.
Value_2
An integer or floating point value.
Accuracy
An integer or floating point value.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).
Note: When the difference between value_1 and value_2 is greater than accuracy, the test fails.


3. null value test (nil tests)


Stassertnil

Fails the test case when a given expression is not nil.
If the given expression is not nil, the test fails.
Stassertnil (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Stassertnotnil

Fails the test case when a given expression is nil.
If the expression is nil, the test fails.
Stassertnotnil (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).


4. boolean test (Boolean tests)

Stasserttrue

If the given expression is false, the test fails.
Stasserttrue (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Stassertfalse

If the given expression is true, the test fails.
Stassertfalse (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).


5. Exception test (exception tests)

Stassertthrows

Test fails if the expression does not throw an exception
Stassertthrows (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Stassertthrowsspecific

Test fails when the expression cannot throw exceptions of a specific class.
Stassertthrowsspecific (expression, exception_class, failure_description ,...)

Parameters
Expression
The expression to be tested.
Prediction_class
Exception
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Note: The test fails if expression does not throw an exception_class exception.

Stassertthrowsspecificnamed

If the expression cannot throw an exception of the specified name of a specific class, the test fails.
Stassertthrowsspecificnamed (expression, exception_class, exception_name, failure_description ,...)

Parameters
Expression
The expression to be tested.
Prediction_class
Exception
Prediction_name
Exception name string
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

NOTE: If expression cannot throw an exception named prediction_name in the prediction_class class, the test fails.

Stassertnothrow

If the expression throws an exception, the test fails.
Stassertnothrow (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Stassertnothrowspecific

Test fails when the expression throws an exception of a specific class.
Stassertnothrowspecific (expression, exception_class, failure_description ,...)

Parameters
Expression
The expression to be tested.
Prediction_class
Exception
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Note: The test fails when expression throws an exception_class exception.

Stassertnothrowspecificnamed

If the expression throws an exception of the specified name of a specific class, the test fails.
Stassertnothrowspecificnamed (expression, exception_class, exception_name, failure_description ,...)

Parameters
Expression
The expression to be tested.
Prediction_class
Exception
Prediction_name
Exception name string
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Note: When expression throws an exception named prediction_name in the prediction_class class, the test fails.

Stasserttruenothrow

If the expression is false or an exception is thrown, the test fails.
Stasserttruenothrow (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Stassertfalsenothrow

If the expression is true or an exception is thrown, the test fails.
Stassertfalsenothrow (expression, failure_description ,...)

Parameters
Expression
The expression to be tested.
Failure_description
Specifies the format string of your error message, which can be nil
...
(Optional) Replace the failure_description parameter list with commas (,).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.