-
XCode의 The Basic of Unit Test - 유닛테스트 기본앱등이에게 살충제를 뿌린다./일기는 일기장에 2017. 1. 9. 18:35
<아무 이유 없이 경리>
Writing Test Methods
You add tests to a test class by writing test methods. A test method is an instance method of a test class that begins with the prefix test, takes no parameters, and returns
void
, for example,(void)testColorIsRed()
. A test method exercises code in your project and, if that code does not produce the expected result, reports failures using a set of assertion APIs. For example, a function’s return value might be compared against an expected value or your test might assert that improper use of a method in one of your classes throws an exception. XCTest Assertions describes these assertions.For a test method to access the code to be tested, import the corresponding header files into your test class.
When Xcode runs tests, it invokes each test method independently. Therefore, each method must prepare and clean up any auxiliary variables, structures, and objects it needs to interact with the subject API. If this code is common to all test methods in the class, you can add it to the required
setUp
andtearDown
instance methods described in Test Class Structure.Here is the model of a unit test method:
- (void)testColorIsRed {
// Set up, call test subject API. (Code could be shared in setUp method.)
// Test logic and values, assertions report pass/fail to testing framework.
// Tear down. (Code could be shared in tearDown method.
}
And here is a simple test method example that checks to see whether the
CalcView
instance was successfully created for SampleCalc, the app shown in the Quick Start chapter:- (void) testCalcView {
// setup
app = [NSApplication sharedApplication];
calcViewController = (CalcViewController*)[NSApplication sharedApplication] delegate];
calcView = calcViewController.view;
XCTAssertNotNil(calcView, @"Cannot find CalcView instance");
// no teardown needed
}
'앱등이에게 살충제를 뿌린다. > 일기는 일기장에' 카테고리의 다른 글
Peek and Pop 코드 (0) 2017.06.06 [iOS/Swift/AVFoundation] 카메라를 붙이며 알게된 것, + 알아볼 것 (0) 2017.03.16 NSAttributedString, NSRange 를 부탁해 (1) 2016.12.20 [iOS] numberItemsInSection에서 왜이렇게 크래쉬가? (0) 2016.12.16 [iOS10] viewWillAppear와 viewWillLayoutSubviews (0) 2016.11.29