组合
组合 是一个用于iOS测试的实用框架,适用于快速 边界测试。
边界测试 或 边界值分析,涉及使用输入域的极端值生成测试案例,例如最大、最小、刚刚在/外边界上,典型值和错误值。它类似于等价类划分,但侧重于“角落案例”。
该框架只做了两件事
- 从测试数据输入集中生成一组组合;
- 为每个组合生成运行时单元或UI测试;
查阅API参考以获取更多信息。
简单示例
我们有一个包含四个字段的输入表单:姓名首字母、电子邮件、密码和性别。
我们还为每个字段定义了测试边界值
- 姓名首字母:
John Smith,空字符串 - 电子邮件:
[email protected]、john.smith@、空字符串 - 密码:
12345、~@#123ABC、空字符串 - 性别:
男性、女性
组合 从输入测试数据值中获得一组,并将其转换为为生成的每个值组合的 运行时测试。
所以,在我们的例子中,组合将是
- [
John Smith,[email protected],12345,男性] - [
John Smith,[email protected],12345,女性] - [%code]John Smith%code%
[email protected],%code~@#123ABC%code%,%code男%code% - [%code]John Smith%code%
[email protected],%code女%code% - 等等。
对于每一种组合,都会生成一个测试用例(%code%XCTestCase%code%)。
UI测试组合生成的运行示例。
安装
Carthage
如果您正在使用 %strong>Carthage%strong%,您可以在您的 %code>Cartfile%code% 中添加以下行,以在您的 workspace 中构建库。
github "alexmx/Combinations"
CocoaPods
如果您正在使用 %strong>CocoaPods%strong%,您可以在 %code>Podfile%code% 中添加以下行,以集成库。
platform :ios, '8.0'
use_frameworks!
target 'YourAppTarget' do
pod "Combinations"
end手动安装
要将 %strong>Combinations%strong%library 引入库,您需要从提供的源代码构建一个动态框架,并将其包含到您的项目中,或者将其整个 %strong>Combinations%strong%library 作为子项目通过将其复制到项目目录中,或者通过 Git 子模块包含。
使用方法
该库只需要重写两个方法:%code>valuesForCombinations%code% 和 %code>assertCombination:%code%
import XCTest
import Combinations
class MyTests: CombinationsSpec {
override func setUp() {
super.setUp()
}
// Provide input values for Combinations
override class func valuesForCombinations() -> [[Any]]? {
return [
[1, 2, 3, 4],
["John Smith", "John", ""]
]
}
// This method will be called for each generated combination:
// [1, "John Smith"], [1, "John"], [1, ""], [2, "John Smith"], etc.
override func assertCombination(_ combination: [Any]) {
// Perform required asserts on combination
}
}许可证
本项目采用MIT许可证条款授权。查看LICENSE文件。

