XCETesting 1.2.0

XCETesting 1.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最后发布2017年9月
SwiftSwift版本3.1
SPM支持SPM

Maxim Khatskevich维护。



  • Maxim Khatskevich

问题

每个单元测试代表一个或多个需求。标准的 Xcode API(XCTest 框架)提供了一些基本表达式,它们可以很好地工作,但结果代码不够简洁、易于阅读和理解。

愿望清单

  1. 使结果代码更简洁且自描述;
  2. 允许将需求表示为闭包(因此它可以是单个值、表达式或多个表达式的组合);
  3. 允许从检查中返回值。

如何安装

建议使用 CocoaPods 安装。

工作原理

该库提供了一些辅助函数,每个函数都接受需求描述和闭包,这些闭包将返回将要评估(并返回给某些函数)的值。

如何使用

当您拥有一个 Optional 值或您有一个会生成 Optional 值的函数/闭包,并且只有在它不是 nil 的情况下才需要这个值,否则调用 XCTFail

let nonNilValue = try RXC.value("Value is NOT nil") {
	
	// return here an optional value,
	// it might be result of an expression 
	// or an optional value captured from the outer scope,
	// will call 'XCTFail' if value IS 'nil' or just return
	// non-Optional value overwise
}

与上述代码相同,但不返回任何内容。当您有一个 Optional 值或您有一个生成 Optional 值的函数/闭包,并且您需要确保这个值不是 nil,否则调用 XCTFail

try RXC.isNotNil("Value is NOT nil") { // does not return anything
	
	// return here an optional value,
	// it might be result of an expression 
	// or an optional value captured from the outer scope,
	// will call 'XCTFail' if value IS 'nil' or pass through
	// silently otherwise
}

当您有一个 Optional 值或您有一个生成 Optional 值的函数/闭包,并且您需要确保这个值是 nil,否则调用 XCTFail

try RXC.isNil("Value IS nil") { // does not return anything
	
	// return here an optional value,
	// it might be result of an expression 
	// or an optional value captured from the outer scope,
	// will call 'XCTFail' if value is NOT 'nil' or pass through
	// silently otherwise
}

当您有一个 Bool 值或您有一个生成 Bool 值的函数/闭包,并且您只想在它是 true 的情况下继续,否则调用 XCTFail

try RXC.isTrue("Value is TRUE") { // does not return anything
	
	// return here a boolean value,
	// it might be result of an expression 
	// or an boolean value captured from the outer scope,
	// will call 'XCTFail' if value is 'false' or pass through
	// silently otherwise
}

VerificationFailed 数据类型只有一个参数

  • let description: String,它包含传递给相应 RXC.* 函数的需求描述。