【发布时间】:2017-05-15 17:30:43
【问题描述】:
我正在练习 TDD,我马上就遇到了一个非常简单的错误,但不知道为什么。这是该项目的第一个单元测试用例,当我认为我已按预期准备好所有东西时,它不会编译。
单元测试用例代码如下:
import XCTest
@testable import PassionProject
class ToDoItem: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func test_Init_TakesTitle(){
ToDoItem(title: "Instance Ones Title")
}
}
通过在适当的目标中创建一个 ToDoItem 类,模型就位,代码如下:
struct ToDoItem {
let title: String
}
在搜索 stackoverflow 后,其他答案通过确保为 Swift 3 列出参数名称来解决此错误,并且 stackoverflow 上的其他示例针对返回类型的函数。在此示例中,我没有返回类型,并且在创建实例时列出了参数名称。有人可以指出我做错了什么的方向,其次,Xcode 在说“任何可用的重载”时是什么意思?我的在线搜索找到了关于函数重载的教程,但结构不是函数,对吧?
提前感谢您提供任何解释,以了解 Xcode 在此示例中的确切含义。
【问题讨论】:
标签: swift xcode unit-testing tdd xctest