[英]How do I exclude a code path when running a unit test on iOS?
I have some code that throws an exception when run from a logic test in ocunit. 从ocunit中的逻辑测试运行时,我有一些引发异常的代码。 I would like to ignore this code and test the rest of the functionality without having to setup an application test nor having to decompose the method. 我想忽略此代码并测试其余功能,而不必设置应用程序测试或分解方法。
For example: 例如:
-(void)testMethod {
BOOL result = NO;
UIFont * font = [UIFont systemFontOfSize:12]; //throws exception in ocunit
...
return result;
}
How can I call this from a unit test with the UIFont creation excluded? 如何从排除UIFont创建的单元测试中调用此方法?
Wrap the UIFont call in an if block and use NSClassFromString to dynamically load a SenTestCase class. 将UIFont调用包装在if块中,并使用NSClassFromString动态加载SenTestCase类。
example: 例:
-(void)testMethod {
BOOL result = NO;
if(!NSClassFromString(@"SenTestCase")) {
UIFont * font = [UIFont systemFontOfSize:12]; //throws exception in ocunit
}
...
return result;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.