2011年8月9日火曜日

テストデータの利用

テストデータを利用するために Bundle に含めるのだけど、[NSBundle mainBundle] だとテスト用の Bundle ではなくてアプリの方の Bundle を参照するのでよろしくない。
こういう時は、[NSBundle bundleForClass:[MyAppTests class]] などして Bundle を指定してあげるのが良さそうだ。
NSBundle *bundle = [NSBundle bundleForClass:[MyAppTests class]];

//Accurateness test
NSString *path = [bundle pathForResource:@"test_data" ofType:@"txt"];
NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
STAssertTrue([MyApp myMethod:str], @"myMethod");

0 件のコメント:

コメントを投稿