【发布时间】:2010-11-08 20:03:08
【问题描述】:
Objective-C 单元测试是否需要头文件?
在使用 OCUnit、GHUnit 或 GTM 单元测试时,我看不到为单元测试创建头文件的意义。如果我决定更改我的单元测试,这感觉就像是我需要保持更新的另一个文件。
测试在一个文件中是自包含的,我不会在另一个测试文件中引用一组单元测试。
示例:SetupTests.m(使用 GHUnit)
// SetupTests.m
@interface SetupTests : GHTestCase
{}
@end
@implementation SetupTests
- (void) testMath {
GHAssertTrue((1+1)==3, @"Compiler isn't feeling well today :-(" );
}
- (void) testFirstUT {
GHAssertEquals(1, 2, @"Should fail");
}
- (void) testSecondUT {
GHAssertEquals(1, 1, @"Should pass");
}
@end
【问题讨论】:
-
XCode 5.0 在使用向导生成测试类时结合了头文件和实现文件。
-
很高兴知道。这可能不适用于 GHUnit 或其他 3rd 方测试。在我之前的测试中,最好只删除 GHUnit 的 .h。
标签: iphone objective-c unit-testing tdd