介绍
我想测试在视图子视图(作为模拟注入)上设置了正确的框架。
但是我似乎无法找到一种方法来验证是否设置了正确的 CGRect
当前尝试
-(void)testThatCorrectFrameIsSet {
//Arrange
MKTArgumentCaptor *argumentCaptor = [[MKTargumentCaptor alloc] init];
self.sut.subView = mock([UIView class]);
//Act
[self.sut awakeFromNib];
//Assert
[[[MKTVerify(self.sut.subView) withMatcher:[argumentCaptor capture]] setFrame:CGSizeZero];
expect([argumentCaptor.value CGRectValue].size.x).to.beCloseToWithin(42, 0.001);
}
出了什么问题
我得到:
"NSInvalidArgumentException", "-[_NSInlineData CGRectValue]: unrecognized selector sent to instance 0x7af325c0"
这让我想知道如何正确捕获 CGRect 值
边注
我知道我可以注入一个实际的 UIView 而不是一个模拟的,但是我正在测试的实际代码阻止我这样做,因为这会使这个问题变得比需要的更难。