Skip to content

Commit

Permalink
Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Onetaway committed Sep 12, 2014
1 parent 3d777a9 commit afdce22
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 5 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ iOS 测试

###目录

* [如何编写单元测试](#如何编写单元测试)
* [定义测试范围](#定义测试范围)
* [测试性能](#测试性能)
* [测试应用程序和库](#测试应用程序和库)
* [XCTest—Xcode的测试框架](#XCTest—Xcode的测试框架)
* [测试应该从何处开始](#测试应该从何处开始)
* [断言分类](#断言分类)
* [测试性能](#测试性能)
* [测试应用程序和库](#测试应用程序和库)
* [XCTest—Xcode的测试框架](#XCTest—Xcode的测试框架)
* [测试应该从何处开始](#测试应该从何处开始)
* [断言分类](#断言分类)

* [无条件失败](#无条件失败)
* [相等性测试](#相等性测试)
* [为空测试](#为空测试)
* [布尔型测试](#布尔型测试)
* [异常测试](#异常测试)

###如何编写单元测试
1. 前提。在编写单元测试中,首先要记住的是***识别出你的程序需要做什么***。在我知道我需要什么之后,我就能够决定我需要什么样的代码来实现我的需求。这些代码将会成为测试的主体。
2. ***用已知的输入运行代码***。单元测试的一个重要的特性就是它应当是可重复的。无论何时,也无论在什么计算机上,如果测试代码正确,它就应该通过,否则就应该失败。
3. ***观察期望得到的结果***
4. ***校验结果***
5. ***重构***





###定义测试范围


Expand Down
Binary file modified Test-Driven iOS Development.pdf
Binary file not shown.
15 changes: 15 additions & 0 deletions iOS TDD Study/StackOverflowManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// StackOverflowManager.h
// iOS TDD Study
//
// Created by sanlen on 9/12/14.
// Copyright (c) 2014 Onetaway. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface StackOverflowManager : NSObject

@property (nonatomic, weak) id<StackOverflowManagerDelegate> delegate;

@end
21 changes: 21 additions & 0 deletions iOS TDD Study/StackOverflowManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// StackOverflowManager.m
// iOS TDD Study
//
// Created by sanlen on 9/12/14.
// Copyright (c) 2014 Onetaway. All rights reserved.
//

#import "StackOverflowManager.h"

@implementation StackOverflowManager

- (void)setDelegate:(id<StackOverflowManagerDelegate>)delegate {
if (![delegate conformsToProtocol: @protocol(StackOverflowManagerDelegate)]) {
[[NSException exceptionWithName:NSInvalidArgumentException reason:@"object doesn't conform to the protocol" userInfo:nil] raise];
}

_delegate = delegate;
}

@end
93 changes: 93 additions & 0 deletions iOS TDD StudyTests/QuestionCreationTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// QuestionCreationTests.m
// iOS TDD Study
//
// Created by sanlen on 9/12/14.
// Copyright (c) 2014 Onetaway. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "StackOverflowManager.h"

@interface QuestionCreationTests : XCTestCase

@property (nonatomic, strong) StackOverflowManager *mgr;

@end

@implementation QuestionCreationTests

- (void)setUp {
[super setUp];

_mgr = [[StackOverflowManager alloc] init];
}

- (void)tearDown {

_mgr = nil;

[super tearDown];
}


- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}

- (void)testNonConformingObjectCannotBeDelegate {

XCTAssertThrows(self.mgr.delegate = (id <StackOverflowManagerDelegate>)[NSNull null], @"NSNull should not be used as the delegate as doesn't comform to the delegate protocol.");
}

- (void)testConformingObjectCanBeDelegate {
id<StackOverflowManagerDelegate> delegate = [[MockStackOverFlowManagerDelegate alloc] init];


XCTAssertNoThrow(self.mgr = delegate, @"object conforming to delegate protocol ccan be used as the delegate");
}

- (void)testManagerAcceptsNilAsADelegate {
XCTAssertNoThrow(self.mgr = nil, @"It should be accept to use nil as a delegate");
}

@end


































0 comments on commit afdce22

Please sign in to comment.