Rudolf Adamkovič
Rudolf Adamkovič

Reputation: 31486

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);
}

Upvotes: 1

Views: 508

Answers (2)

Austin
Austin

Reputation: 5655

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.

Upvotes: 1

Gabriele Petronella
Gabriele Petronella

Reputation: 108101

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.

Upvotes: 0

Related Questions