简体   繁体   中英

Unit-testing superclass

I'm trying to figure out how to rewrite the following Objective-C unit-test in Swift :

- (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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM