Reputation: 186
I have a struct (partial)
struct Event : JSONSerializable, Glossy {
let name : String
let start : String
private var startTimeZone: String
let finish : String
private var finishTimeZone: String
that when called from UnitTest:
func testReal() {
let event : Event = Event()
let editor = EventEditor(forEvent: Event())
XCTAssertNotNil(editor)
}
throws compile error: Cannot convert value of type 'Event' to expected arguement type 'Event'
EventEditor is:
import Foundation
class EventEditor {
let event : Event
init(forEvent event: Event) {
self.event = event
}
}
But if when called from product (aka outside if unit tests) it works just fine with no errors or issues. JSONSerializable -- helper extensions to convert to/from JSON Glossy -- cocoapod for json parsing.
I've tried created a stripped down version of Event and adding pieces (eg JSONSerializable, Glossy)
Can anyone suggest why this wouldn't work in XCTest but works in other code?
Upvotes: 1
Views: 809
Reputation: 9362
Very possibly you have added the file that contains the Event
struct to both your main target and your test target.
To check if this is the case, select the file in the Project navigator, then show the Utilities pane on the right, and check the Target Membership. If your test target is checked, uncheck it.
In your XCTest file, add @testable import YourMainTargetNameHere
to the top of the file.
Upvotes: 6