我想创建单元测试以确保程序集的配置对某些键具有正确的值。
程序集声明它的配置如下:
- (id)config
{
return [TyphoonDefinition configDefinitionWithName:@"SomeConfigFile.plist"];
}
并设置一些对象的属性,如下所示:
[initializer injectParameterWith:TyphoonConfig(@"some.config.key")];
我想用正确的钥匙检查装配是否正确,我。即像这样(伪代码):
assertEquals([myAssembly configValueForKey:@"some.config.key"], @"correct key value");
如何实现这一目标?
答案 0 :(得分:0)
我们建议您在从Typhoon发出对象后为其创建集成测试。其中一个测试是对象处于所需的初始状态:
@implementation MyTestCase
{
TyphoonBlockComponentFactory *_factory;
}
- (void)setUp
{
//Recommend putting this in a common place, so main test assembly only has to be set up once
_factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[
[ApplicationAssembly assembly],
[CoreComponents assembly],
[PersistenceComponents assembly],
[NetworkComponents assembly]
]];
TyphoonConfigPostProcessor *postProcessor = [[TyphoonConfigPostProcessor alloc] init];
[postProcessor useResourceWithName:@"Config.plist"];
[factory attachPostProcessor:postProcessor];
}
//Assuming a classroom configured with a teacher count from Config.plist
- (void)test_classroom_should_initially_have_one_teacher
{
CoreComponents *components = [factory asAssembly];
ClassRoom *classRoom = [factory classroom];
XCTAssertEquals(1, classroom.numberOfTeachers);
}
。 。 。从这里开始,您可以继续为组件编写其他集成测试。
集成测试指南: