Typhoon 是一款出色的工具,Rambler&Co 的 iOS 团队非常喜欢它。除了实际贡献之外,我们还开发了一些有用的工具,它们不能包含在主项目中。
RamblerInitialAssemblyCollector
- 这个类可以在启动时激活组件,而不是通过 plist 集成。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 文件。