unit test
TRANSCRIPT
How?1.Code
2.Add Tests
3.Modify code for passing Tests
Vs
4.Write Tests
5.Write code that pass Tests (Test-Driven Development)
XCTestSubclass XCTestCase
Implement Test method
(Beginning with “test”)
- (void)testMyMethodWorks
Use Assertion (Macro) APIs to report failures
- XCTAssertEqual(value, expectValue);
Test TargetTest Target:
- Test code
- Resources
Automatically included in new project
Existing projects can add test targets
Asynchronous TestingCreate Expectation Object:
- XCTestExpectation *expectation = [self expectationWithDescription:@"Load Data"];
XCTestCase waits for Expectations to “Fullfill”- (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(nullable
XCWaitCompletionHandler)handler;
Handle when finishing asynchronous tasks:- [expectation fulfill];
Performance TestingHow to measure app performance?
How to find which part causes performance problem?
=> Performance Testing.
Measuring PerformanceTest code block:
- (void)measureBlock:(void (^)(void))block;
Runs code block 10 time
Measures time
Results show in Xcode
Setting BaselinesBaselines is Average run time
Detect Regressions:
- Fail if (Baselines Average)>0.1 seconds and >10%
Baselines are stored in sources
Baselines are per-device configuration:
- Device model, CPU, OS
Standard DeviationWhy STDDEV too big?
- File I/O, Network I/O?
- Initialization?
- Does it do the same work each time it's called?
- System busy?
ReferenceWWDC’s video: https://developer.apple.com/videos/play/wwdc2014/414/
Unit Test Sample: https://developer.apple.com/library/mac/samplecode/UnitTests/History/History.html#//apple_ref/doc/uid/DTS40011742-RevisionHistory-DontLinkElementID_1
Udacity Course: https://www.udacity.com/course/viewer#!/c-cs212/l-48688918/m-48276959
Demo Source: https://www.dropbox.com/s/mhjpllmxugyf02c/UnitTest.zip?dl=1
QA?1.How to implement UITest?
- Checkout apple’s Sample app: https://developer.apple.com/library/mac/samplecode/UnitTests/History/History.html#//apple_ref/doc/uid/DTS40011742-RevisionHistory-DontLinkElementID_1
- Checkout this WWDC session: https://developer.apple.com/videos/play/wwdc2015/406/