iOS

Xctest单元测试target中添加的资源无法通过NSBundle获取到

简介:Xctest单元测试target中添加的资源无法通过NSBundle获取到

Xctest单元测试target中添加的资源无法通过NSBundle获取到的解决方案

下面代码,在Xctest target 中 获取bundle 下面的资源文件路径为nil

- (void)testLocalScript {
  NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
  [RTAutomationManger readFileToScript:path];
  [RTAutomationManger setRecordStatus:ENUM_APPSTATE_PLAY];
  [RTAutomationManger playRecordAndRecognizeImage];
}

解决方案:
- (void)testLocalScript {
NSString *path = [NSBundle bundleForClass:[self class]];
[RTAutomationManger readFileToScript:path];
[RTAutomationManger setRecordStatus:ENUM_APPSTATE_PLAY];
[RTAutomationManger playRecordAndRecognizeImage];
}
```

推荐阅读

目录