【发布时间】:2014-12-09 03:43:03
【问题描述】:
我正在尝试使用 XCTest 编写一个测试来驱动 drawRect 方法的自定义实现的实现,但我不确定如何执行此操作。
由于测试,我希望编写的代码如下:
- (void)drawRect:(CGRect)rect
{
CGPoint startOfHorizontalLine = (CGPointMake(1.0f, 0.0f));
CGPoint endOfHorizontalLine = (CGPointMake(1.0f, 10.0f));
UIColor * lineColour = [UIColor colorWithRed:40.0f/255.0f green:34.0f/255.0f blue:34.0f/255.0f alpha:1.0f];
[lineColour setStroke];
UIBezierPath *horizontalLine = [UIBezierPath bezierPath];
[horizontalLine moveToPoint:startOfHorizontalLine];
[horizontalLine addLineToPoint:endOfHorizontalLine];
[horizontalLine stroke];
}
如果我需要使用模拟库,我已经对 OCMock 进行了一些研究。
感谢您的帮助。
【问题讨论】:
-
XCTest 用于逻辑测试,而不是基于 UI 的测试。
标签: ios unit-testing ocmock xctest