1

I'm using Kiwi to test some classes and I need to stub a class method just to return a fake file path. I know that i can solve exposing some path property or create a subclass just for test, but i prefere to keep only one class and stub some methods.

this is the test:

it(@"return the full list of POS", ^(){
    NSString *sample_data_path = [[NSBundle bundleForClass:[self class]] pathForResource:@"sample_pos" ofType:@"plist"];
    Class p = [PointOfSale class];
    [p stub:@selector(sampleDataPath) andReturn:sample_data_path];
    NSArray *allPos = [p findAll];
    [[theValue([allPos count]) should] equal:theValue(100)];
});

I'm confused because this test pass and fail alternatively, one success and one failure. There is not any "before_each"or other running test...

someone has the same issue?

4

1 回答 1

0

我找到了这个问题的原因。原始和存根类中的方法sampleDataPath返回一个文件路径,该路径应该位于不同的包(主包和测试包)中。但是即使是“生产”文件也被复制到了测试包中,所以我们在同一个包中有两个同名的文件,因此测试的结果是不可预测的;)

所以....如果您有这样的问题,请仔细检查您的文件名!

于 2014-03-19T08:03:50.833 回答