1

テストケース内にファクトリを作成しています

        + (TyphoonComponentFactory*)integrationTestFactory
{
    static TyphoonComponentFactory* factory;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^
    {
        factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[
            [MainAssembly assembly],
            [Kernel assembly],
            [NetworkComponents assembly],
            [PersistenceComponents assembly]
        ]];

        //Other config here. . . 
        TyphoonConfigPostProcessor *configurer = [TyphoonConfigPostProcessor configurer];
        [configurer useResourceWithName:@"testConfig.properties"];
        [factory attachPostProcessor:configurer];
        //this may be necessary
        [factory makeDefault 

    });
    return factory;
}

次に、それにアクセスします

  - (void)setUp
{
    [super setUp];

    factory_instance = [LoginTest integrationTestFactory];
}

最後にアセンブリにアクセスすると、構成キーが構成されていないというエラー値が返されます

DAO *dataManager = [(DaoAssembly*)factory_instance DAO];

組み立ては以下の通り

-(id)DAO {

return [TyphoonDefinition withClass:[DAO class] configuration:^(TyphoonDefinition* definition)
        {
            [definition useInitializer:@selector(shareManager)];
            [definition injectProperty:@selector(apikey) with:TyphoonConfig(@"api.key")];
            [definition injectProperty:@selector(dataParser) with:[self dataParser]];
            definition.scope = TyphoonScopeSingleton;

        }];

}

4

1 に答える 1

0

次のテスト ケースで確認したとおり、お客様が経験していることを再現できません。

この簡単な例を自分で試してみてください。おそらく、問題が何であるかが明らかになるでしょう。

いくつかのProperties.properties:

damsels.rescued=12

Knight.h/.m:

@interface Knight : NSObject

@property(nonatomic) NSUInteger damselsRescued;

@end

MyAssembly.m:

- (id)knight
{
    return [TyphoonDefinition withClass:[Knight class] configuration:
        ^(TyphoonDefinition *definition) {
        [definition injectProperty:@selector(damselsRescued)
             with:TyphoonConfig(@"damsels.rescued")];        
    }];
}

IntegrationTests.m:

@interface IntegrationTests : XCTestCase
{
    TyphoonComponentFactory *_factory;
}


@end

@implementation IntegrationTests

+ (TyphoonComponentFactory *)integrationTestFactory
{
    static TyphoonComponentFactory *factory;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[
            [MyAssembly assembly],
        ]];

        //Other config here. . .
        TyphoonConfigPostProcessor *configurer = [TyphoonConfigPostProcessor configurer];
        [configurer useResourceWithName:@"SomeProperties.properties"];
        [configurer useResourceWithName:@"SomeOtherProperties.properties"];
        [factory attachPostProcessor:configurer];
        [factory makeDefault];
    });
    return factory;
}


- (void)setUp
{
    _factory = [IntegrationTests integrationTestFactory];
}

- (void)testPropertiesAreSet
{
    Knight *knight = [(InfrastructureComponentsAssembly *) _factory knight];
    XCTAssertEqual(knight.damselsRescued, 12);
}

@end
于 2014-06-18T03:03:37.763 に答える