如何检查Typhoon程序集配置是否包含某些键的值?

时间:2014-10-15 13:53:44

标签: objective-c unit-testing typhoon

我想创建单元测试以确保程序集的配置对某些键具有正确的值。

程序集声明它的配置如下:

- (id)config
{
    return [TyphoonDefinition configDefinitionWithName:@"SomeConfigFile.plist"];
}

并设置一些对象的属性,如下所示:

[initializer injectParameterWith:TyphoonConfig(@"some.config.key")];

我想用正确的钥匙检查装配是否正确,我。即像这样(伪代码):

assertEquals([myAssembly configValueForKey:@"some.config.key"], @"correct key value");

如何实现这一目标?

1 个答案:

答案 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);

}


。 。 。从这里开始,您可以继续为组件编写其他集成测试。

集成测试指南:

  • 这是关于integration testing in Typhoon的指南。
  • 您可以测试TyphoonConfig管道,但测试由程序集构建的对象侧重于需求(BDD),并提供程序集所有方面的隐式覆盖。