Unit Test获取bundle路径

如何在Unit Test中获取bundle Path

最近在做上传图片Unit Test的时候,发现单元测试总是执行不通。把代码放到Main target中结果是正确的,无奈之下只能在Test Target中debug,惊奇的发现不能通过[NSBundle mainBundle]获取到文件的路径,搜索一圈发现必须通过bundleForClass才能获取到正确的位置。

NSBundle *testBundle = [NSBundle bundleForClass:[YourTestClass class]];
NSString *testBundlePath = [testBundle bundlePath];

你可能感兴趣的:(Unit Test获取bundle路径)