UITest common assertions for unit tests

Source: Internet
Author: User

xctfail (Format ...) generates a failed test; Xctfail (@"Fail"); Xctassertnil (A1, format ...) for null judgment, A1 is empty when passed, and vice versa; Xctassertnil (@"Not nil string",@"string must be nil"); Xctassertnotnil (A1, Format ...) is not null-judged, A1 is not empty when passed, and vice versa; Xctassertnotnil (@"Not nil string",@"string can not is nil"); Xctassert (expression, format ...) is passed when expression evaluates to true; Xctassert (2>2),@"expression must be true"); Xctasserttrue (expression, format ...) is passed when expression evaluates to true; Xctasserttrue (1,@"Can not is zero"); Xctassertfalse (expression, format ...) is passed when expression evaluates to false; Xctassertfalse (2<2),@"expression must be false"); Xctassertequalobjects (A1, A2, Format ...) is judged equal, [A1 ISEQUAL:A2] value is true when passed, one of which is not empty when not passed; Xctassertequalobjects (@"1",@"1",@"[A1 ISEQUAL:A2] should return YES"); Xctassertequalobjects (@"1",@"2",@"[A1 ISEQUAL:A2] should return YES"); Xctassertnotequalobjects (A1, A2, Format ...), the value of [A1 ISEQUAL:A2] is false when passed, Xctassertnotequalobjects (@"1",@"1",@"[A1 ISEQUAL:A2] should return NO"); Xctassertnotequalobjects (@"1",@"2",@"[A1 ISEQUAL:A2] should return NO"); Xctassertequal (A1, A2, Format ...) Judge Equality (when A1 and A2 are C scalar, struct, or union use, the actual test found NSString can also);1. Compare basic data type variable xctassertequal (1,2,@"a1 = A2 shoud be true");//failed to pass the testXctassertequal (1,1,@"a1 = A2 shoud be true");//Pass the test 2. Compare NSString Objects NSString*STR1 =@"1"; NSString*STR2 =@"1"; NSString*STR3 =str1; Xctassertequal (str1, str2,@"A1 and A2 should point to the same object");//Pass the testXctassertequal (str1, STR3,@"A1 and A2 should point to the same object");//Pass the test 3. Compare Nsarray objects Nsarray*array1 = @[@1]; Nsarray*array2 = @[@1]; Nsarray*array3 =array1; Xctassertequal (Array1, Array2,@"A1 and A2 should point to the same object");//failed to pass the testXctassertequal (Array1, Array3,@"A1 and A2 should point to the same object");//Pass the testxctassertnotequal (a1, A2, Format ...) judgment unequal (used when A1 and A2 are C scalar, struct, or union); Xctassertequalwithaccuracy (A1, a2, Accuracy, Format ...) The judgment is equal, (double or float type) provides an error range when in the error range (+/-accuracy) pass the test within equal time; Xctassertequalwithaccuracy (1.0f,1.5f,0.25f,@"A1 = A2 in accuracy should return YES");    Xctassertnotequalwithaccuracy (A1, a2, accuracy, Format ...) The judgment is unequal, (double or float type) provides an error range, which passes the test when the error range is not equal; Xctassertnotequalwithaccuracy (1.0f,1.5f,0.25f,@"A1 = A2 in accuracy should return NO"); Xctassertthrows (expression, format ...) exception test, passed when expression has an exception; (very perverted) xctassertthrowsspecific (expression, Specificexception, Format ...) Exception tests, which pass when expression has an specificexception exception, and other exceptions or exceptions that do not occur; xctassertthrowsspecificnamed (expression, Specificexception, Exception_name, Format ...) Exception test, when expression has a specific exception, the exception of the specific exception name passed the test, and vice versa; Xctassertnothrow (expression, format ...) exception test, passing the test when expression does not occur abnormally; Xctassertnothrowspecific (expression, specificexception, format ...) Exception test, when expression does not have a specific exception, the specific exception name of the exception passed the test, and vice versa; xctassertnothrowspecificnamed (expression, specificexception, Exception_name, Format ...) An exception test that passes the test when expression does not have an exception that has a specific exception, a specific exception name, and vice versa .

UITest common assertions for unit tests

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.