1

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

大会声明它的配置是这样的:

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

并像这样设置一些对象的属性:

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

我想检查程序集是否使用正确的密钥,即像这样(伪代码):

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

如何做到这一点?

4

1 回答 1

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

}


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

集成测试指南:

  • 这是关于Typhoon 集成测试的指南。
  • 您可以测试 TyphoonConfig 管道,但测试由程序集构建的对象侧重于需求 (BDD),并提供对程序集所有方面的隐式覆盖。
于 2014-10-15T23:37:55.900 回答