Search code examples
objective-cunit-testingtyphoon

How to check that Typhoon assembly config contains value for some key?


I want to create unit test to ensure that assembly's config has correct value for some key.

Assembly declares it's config like this:

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

and sets some objects' properties like this:

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

And I want to check that assembly does so with correct key, i. e. like this (pseudocode):

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

How to achieve this?


Solution

  • We recommend that you create integration tests for your object, after it is emitted from Typhoon. One of these tests will be that the object is in the required initial state:

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


    . . . from here you can go on and write other integration tests for your component.

    Integration Testing Guide:

    • Here's a guide about integration testing in Typhoon.
    • You could test the TyphoonConfig plumbing, but testing the objects that get built by the assembly focuses on requirements (BDD), and provides implicit coverage of all aspects of the assembly.