iOS-單元測試

iOS進階之單元測試-視頻

概念

邏輯錯誤,通過斷言XCTAssertEqual
TDD,測試驅動開發

shift+Command+0(開發者文檔)

調用順序:

+(void)setUp;
-(void)setUp;//把杯子裏面的水倒乾淨,重新進行測試。
-(void)testExample;
-(void)tearDown;
-(void)setUp;
-(void)testPerformanceExample;
-(void)tearDown;

測試的基本結構

1.Given (創建測試添加。數據、初始化的對象、值。OCMock(用來創建測試條件))
2.When (測試方法的參數裏面。)
3.Then (斷言,是否符合預期。)

eg:

//1.Given
    XCTestExpectation *expectation = [self expectationWithDescription:@"Asyn Test is failed"];
    
    //2.When
    ViewController *vc = [ViewController new];
    [vc sendAsynRequest:^{
        //3.Then
        [expectation fulfill];//指定時間內沒有執行這個方法,異常對象就會拋出
    }];
    
    [self waitForExpectationsWithTimeout:2 handler:^(NSError * _Nullable error) {
        NSLog(@"---%@",error.localizedDescription);
    }];

從哪裏開始測試?

測試方法

1.盒子方法。白盒測試,黑盒測試,灰盒測試。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章