我有一个单元测试:
- (void)testFetchTrackByTrackIdIsATrack
{
[self addTrackWithSongId:@"123"];
Track *fetchedTrack = [self.library trackByTrackId:@"123"];
assertThat(fetchedTrack, instanceOf([Track class]));
}
失败了:
file:///Users/elliot/Development/Hark/HarkTests/TestLibrary.m: test failure:
-[TestLibrary testFetchTrackByTrackIdIsATrack] failed: Expected an instance
of Track, but was Track instance <Track: 0x6180001077d0>
我有几个其他测试使用相同的实例检查不同的工作类 - 但我无法确定为什么这不起作用。深入研究:
- (void)testFetchTrackByTrackIdIsATrack
{
[self addTrackWithSongId:@"123"];
Track *fetchedTrack = [self.library trackByTrackId:@"123"];
Class c1 = [fetchedTrack class];
Class c2 = [Track class];
}
调试器报告:
c1 Class Track 0x0000000100012fe0
c2 Class 0x1000b3eb8 0x00000001000b3eb8
注意它怎么看不到这[Track class]
是一个类型的类Track
?当我将相同的逻辑应用于其他通过的单元测试时,它们都报告了正确的类名。
感觉它在运行时没有类元数据,但为什么呢?
还有一些案例:
assertTrue(c1 == c2); // FAIL
assertThat([fetchedTrack classDescription],
equalTo([Track classDescription])); // PASS
assertTrue([fetchedTrack isKindOfClass:[Track class]]); // FAIL