iOS基础

OC 单元测试

2018-06-13  本文已影响0人  鹏飞说
TDD

一条testCase就是一个记录,就是一条测试用例

为了创造测试条件OCMock创造测试条件

https://github.com/erikdoe/ocmock
测试顺序
//类方法 1
+(void)setUp {
    [super setUp];
}
// 6
+(void)tearDown {
    [super tearDown];
}
//对象方法 2 4.5
- (void)setUp {
    [super setUp];
    //不断重置信息
    
    // Put setup code here. This method is called before the invocation of each test method in the class.
}
// 4 5.5
- (void)tearDown {
    [super tearDown];
    //不断重置信息
    
    // Put teardown code here. This method is called after the invocation of each test method in the class.
}
// 3
- (void)testAdd {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.    
}
// 5
- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}
测试三段式
ViewController *vc = [ViewController new];
    Person *p = [Person new];
    /**
     测试的基本结构
     Given  创造测试条件,给一些数据 初始化的一些对象 创造测试条件
     
     When 测试方法的参数里面
     
     Then 断言
     
     */
    int a = 1;
    int b = 2;
    int c;
    c = [vc add:a with:b];
    NSString *someInfoString = [vc showSomeBodyInfos:p];
    // 判断逻辑测试
    XCTAssertEqual(c, 3);
上一篇 下一篇

猜你喜欢

热点阅读