Unit Test获取bundle路径

2016-05-30  本文已影响101人  Ever_Blacks

如何在Unit Test中获取bundle Path

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

NSBundle *testBundle = [NSBundle bundleForClass:[YourTestClass class]];
NSString *testBundlePath = [testBundle bundlePath];
上一篇 下一篇

猜你喜欢

热点阅读