[英]Unit-testing superclass
I'm trying to figure out how to rewrite the following Objective-C unit-test in Swift : 我试图弄清楚如何在Swift中重写以下Objective-C单元测试:
- (void)testSuperclass {
Class superclass = [self.animatedView superclass];
Class expectedSuperclass = [BREAnimatedView class];
XCTAssertEqualObjects(superclass, expectedSuperclass);
}
I suppose you can do 我想你可以做
func testSuperclass() {
val superclass = self.animatedView.superclass
val expectedSuperclass = BREAnimatedView.class()
XCTAssertEqualObjects(superclass, expectedSuperclass)
}
but I'd be glad to see if there's a better way. 但我很高兴看到是否有更好的方法。
I believe this should work: 我相信这应该有效:
func testSuperclass() {
XCTAssert(self.animatedView is BREAnimatedView)
}
It's slightly different than your original condition, which tests if BREAnimatedView
is the direct superclass of the view, whereas this just tests if the view inherits from BREAnimatedView
. 它与原始条件略有不同,后者会测试BREAnimatedView
是否是视图的直接超类,而这只是测试视图是否继承自BREAnimatedView
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.