xctest+ocmock

最近テストコード書くのにはまってます
今日もテストコードのエントリーです

今回は自分のこくばんアプリでテストしてみました
黒板アプリはこちら

https://itunes.apple.com/jp/app/kokuban-pro/id818934135?l=ja&ls=1&mt=8
https://itunes.apple.com/jp/app/kokuban/id453329779?l=ja&ls=1&mt=8

xctestの特徴（自分のイメージ）
・xcode5から登場したもの
・ios7向けに作られた？？ので、depoloyment targetをios6にしてると使えない
・TDD用フレームワーク

かな。他のTDDを使ってるなら、これをわざわざ使う必要はないかと思うけど、どうなんですかね
BDDを使うなら、Kiwiですかね

ocmockはまだ、テスト用のダミーオブジェクトのこと

ocmockはcocoapods使った
プロジェクト以下にファイルを配置

```
server:kokuban20131005 shiratsu$ cat Podfile
platform :ios, '7.0'

target :kokuban20131005Tests, :exclusive => true do
   pod 'OCMock'
end
```

```
pod install
```

でocmockは入るはず
とりあえずocmockで作りまくる

こんな感じになってる

```
#import <XCTest/XCTest.h>
#import "OCMock.h"
#import "ViewController.h"
#import "DrawingView.h"

@interface ViewControllerTests : XCTestCase

@end

@implementation ViewControllerTests{
    ViewController *vc;
    id mockelaser;
    id mockchook1;
    id mockchook2;
    id mockchook3;
    id mockchook4;
    id mockchook5;
    id mockmenu;
    id mockcurdraiwingview;
    id mockpastdraiwingview;
    
}

- (void)setUp
{
    [super setUp];
//    
    //UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    //vc = [storyboard instantiateViewControllerWithIdentifier:@"kokuban_iphone"];
    vc = [[ViewController alloc] init];
    
    //とりあえず、モックを作りまくる
    mockelaser = [OCMockObject mockForClass:[UIButton class]];
    mockchook1 = [OCMockObject mockForClass:[UIButton class]];
    mockchook2 = [OCMockObject mockForClass:[UIButton class]];
    mockchook3 = [OCMockObject mockForClass:[UIButton class]];
    mockchook4 = [OCMockObject mockForClass:[UIButton class]];
    mockchook5 = [OCMockObject mockForClass:[UIButton class]];
    mockmenu    = [OCMockObject mockForClass:[UIButton class]];
    mockcurdraiwingview    = [OCMockObject mockForClass:[DrawingView class]];
    mockpastdraiwingview    = [OCMockObject mockForClass:[DrawingView class]];
    vc.chook1 = mockchook1;
    vc.chook2 = mockchook2;
    vc.chook3 = mockchook3;
    vc.chook4 = mockchook4;
    vc.chook5 = mockchook5;
    vc.menu = mockmenu;
    vc.curDrawingView = mockcurdraiwingview;
    vc.pastDrawingView = mockpastdraiwingview;
    //[self.vc performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    vc = nil;
    [super tearDown];
}

- (void)testExample
{
    //XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
    XCTAssertTrue(TRUE);
}

- (void)testViewController1
{
    XCTAssertTrue(TRUE);
    NSLog(@"%@",vc);
    id mock = [OCMockObject niceMockForClass:UIImage.class];
    BOOL boolWriteFile = [vc writeImage:mock toFile:@"test"];
    NSLog(@"writeval:%d",boolWriteFile);
    
    XCTAssertTrue(boolWriteFile);
}

- (void)testViewWillAppear
{
    [vc viewWillAppear:YES];
    NSLog(@"vc.kokubanMode:%d",vc.kokubanMode);
    XCTAssertTrue(vc.kokubanMode);
}

```
まだ一番したのテストしか試してない（成功した）
ッて感じでゴリゴリ試していこうと思います。

おかしなところがあれば指摘ください。
ソースは全部出来たら、githubにあげようかな