Saturday, 15 February 2014

testing - How do I set up unit tests in Swift? -



testing - How do I set up unit tests in Swift? -

i'm having problem adding unit tests swift project of mine, created fresh xcode test project stripped-down version of class:

class simpleclass { allow x: string init(x: string) { self.x = x } convenience init(dict: dictionary<string, string>) { self.init(x: dict["x"]!) } }

then created simple test case:

import xctest import testproblem class testproblemtests: xctestcase { func testexample() { // illustration of functional test case. xctassertequal(simpleclass(x: "foo"), simpleclass(dict: ["x": "foo"])) } }

i had import project (import testproblem) prepare unresolved identifier errors simpleclass.

however, when seek run tests, next compiler error:

could not find overload 'init' accepts supplied arguments

what missing here? calls init work fine outside of xctassertequal call, within test file.

on hunch, tried:

allow x = simpleclass(x: "foo") allow y = simpleclass(dict: ["x": "foo"]) xctassertequal(x, y)

when that, error:

cannot convert expression's type 'void' type 'simpleclass'

did seek define param explicitely ? :

let x : simpleclass = simpleclass(x: "foo") allow y : simpleclass = simpleclass(dict: ["x": "foo"]) xctassertequal(x, y)

unit-testing testing swift

No comments:

Post a Comment