I had problems adding unit tests to my Swift project, so I created a new Xcode test project with a stripped down version of my class:
class SimpleClass {
let x: String
init(x: String) {
self.x = x
}
convenience init(dict: Dictionary<String, String>) {
self.init(x: dict["x"]!)
}
}
Then I created a simple test case:
import XCTest
import TestProblem
class TestProblemTests: XCTestCase {
func testExample() {
XCTAssertEqual(SimpleClass(x: "foo"), SimpleClass(dict: ["x": "foo"]))
}
}
I had to import the project itself ( import TestProblem) to fix unspecified identifier errors for SimpleClass.
However, when I try to run the tests, I get the following compiler error:
Could not find an overload for 'init' that accepts the supplied arguments
What am I missing here? Init calls work fine outside of the call XCTAssertEqual, even in a test file.
On a hunch, I also tried:
let x = SimpleClass(x: "foo")
let y = SimpleClass(dict: ["x": "foo"])
XCTAssertEqual(x, y)
When I do this, I get this error:
Cannot convert the expression type 'Void' to type 'SimpleClass'
source
share