我在一个目标C项目中使用XCTest。
在我的单元测试目标函数中,当收到异常时,我使用NSAssert退出。
即使是预期的这种行为,XCTest仍然将其视为失败。
是否有一种方法可以让XCTest标记这个单元测试应该被断言?
发布于 2022-10-26 21:44:02
使用XCAssertThrow宏测试表达式的任意异常:
- (void)method {
@throw [[NSException alloc] initWithName:@"My Exception" reason:nil userInfo:nil];
}
- (void)testThrows {
XCTAssertThrows([self method], @"The method must throw");
}https://stackoverflow.com/questions/74204988
复制相似问题