RamblerTyphoonUtils 1.5.0

RamblerTyphoonUtils 1.5.0

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布最新发布2016年10月

[etolstoy]维护。



  • 作者:
  • Egor Tolstoy, Irina Dyagileva, Andrey Rezanov, Andrey Zarembo-Godzyatsky 和 Aleksandr Sychev

Typhoon

Typhoon 是一款出色的工具,Rambler&Co 的 iOS 团队非常喜欢它。除了实际贡献之外,我们还开发了一些有用的工具,它们不能包含在主项目中。

  1. RamblerInitialAssemblyCollector - 这个类可以在启动时激活组件,而不是通过 plist 集成。
  2. RamblerTyphoonAssemblyTests - 用于 TyphoonAssembly 测试的基础测试类。

使用

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

组件收集器

首先,使您的组件遵守 RamblerInitialAssembly 协议

@interface ApplicationAssembly : TyphoonAssembly <RamblerInitialAssembly>

@end

然后,不要在 Info.plist 文件中添加此组件,而是在 AppDelegate 中添加以下代码

@implementation AppDelegate

- (NSArray *)initialAssemblies {
    RamblerInitialAssemblyCollector *collector = [RamblerInitialAssemblyCollector new];
    return [collector collectInitialAssemblyClasses];
}

@end

RamblerInitialAssemblyCollector 将在运行时找到您的组件并自动激活它。

组件测试

RamblerTyphoonAssemblyTests 继承您的测试

@interface RamblerApplicationAssemblyTests : RamblerTyphoonAssemblyTests

@property (nonatomic, strong) RamblerApplicationAssembly *assembly;

@end

编写新的测试:每个组件方法一个测试。使用 RamblerTyphoonAssemblyTestsTypeDescriptor 来描述测试对象的类型。请注意,我们不验证块和基本类型:只验证类和协议。

- (void)testThatAssemblyCreatesAppDelegateWithDependencies {
    // given
    Class expectedClass = [RamblerAppDelegate class];
    NSArray *expectedProtocols = @[
                                   @protocol(UIApplicationDelegate),
                                   @protocol(RamblerFooProtocol)
                                   ];
    RamblerTyphoonAssemblyTestsTypeDescriptor *resultTypeDescriptor =
        [RamblerTyphoonAssemblyTestsTypeDescriptor descriptorWithClass:expectedClass
                                                          andProtocols:expectedProtocols];
    NSArray *dependencies = @[
                              RamblerSelector(injectedString),
                              RamblerSelector(injectedPropertyWithProtocols)
                              ];

    // when
    id result = [self.assembly appDelegate];

    // then
    [self verifyTargetDependency:result
                  withDescriptor:resultTypeDescriptor
                    dependencies:dependencies];
}

您正在测试以下内容

  • 目标对象已创建
  • 结果具有所需的类并且符合所需的协议
  • 结果具有所有列出的依赖项
  • 依赖项是正确的类并且符合所需的协议

安装

RamblerTyphoonUtils 通过 CocoaPods 提供。要使用 AssemblyCollector

pod "RamblerTyphoonUtils/AssemblyCollector"

要使用 AssemblyTesting

target 'ProjectNameTargetTests', :exclusive => true do
    pod "RamblerTyphoonUtils/AssemblyTesting"
end 

警告:不要将 AssemblyTesting subspec 包含在主目标中!

许可

RamblerTyphoonUtils 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。

作者