RDSDataSource: Чистые тесты на Swift
- 8. What makes a clean test?
Three things. Readability, readability, and readability.
Robert C. Martin, «Clean Code»
- 23. Custom assertions
func assertIntPairsEqual(actual: (_: Int, _: Int),
expected: (_: Int, _: Int),
file: StaticString = #file,
line: UInt = #line) {
if actual != expected {
XCTFail("Expected (expected) but was (actual)",
file: file, line: line)
}
}
- 24. Custom assertions
func assertIntPairsEqual(actual: (_: Int, _: Int),
expected: (_: Int, _: Int),
file: StaticString = #file,
line: UInt = #line) {
if actual != expected {
XCTFail("Expected (expected) but was (actual)",
file: file, line: line)
}
}
- 25. Custom assertions
func assertIntPairsEqual(actual: (_: Int, _: Int),
expected: (_: Int, _: Int),
file: StaticString = #file,
line: UInt = #line) {
if actual != expected {
XCTFail("Expected (expected) but was (actual)",
file: file, line: line)
}
}
- 51. Partial mocks
class MockURLSession: URLSessionProtocol {
var dataTaskReturnValue: URLSessionDataTask!
func dataTask(with …) -> URLSessionDataTask {
return dataTaskReturnValue
}
}
- 52. Partial mocks
func testExample() {
// given
let mockDataTask = MockURLSessionDataTask()
mockURLSession.dataTaskReturnValue = mockDataTask
// when
…
// then
mockDataTask.verifyResume()
}
- 55. 1.Чистые тесты должны оставаться чистыми
2.Используйте коллекции вспомогательных методов
3.Добавляйте методы проверок к мокам
4.Используйте #file и #line
5.Не мокируйте value types
- 58. 1.Чистые тесты должны оставаться чистыми
2.Используйте коллекции вспомогательных методов
3.Добавляйте методы проверок к мокам
4.Используйте #file и #line
5.Не мокируйте value types
a.sychev@rambler-co.ru
@asychev89