Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift unit test result in unresolved identifier

Simple function in swift for testing:

func testExample() {
    var tagname = "someClass()"
    var logger = Device("", "") //unresolved identifier

    XCTAssert(true, "Pass")
}

Even after I import my module with "import ", I still cannot use classes from my module. Also though I might have messed something up in the project, but NONE of my sample projects will let me use module classes.

Seems like it should work but might have broken in beta 2.

EDIT: fixed it The IDE didn't pick up the check for the param names. Seems Xcode is still a tad iffy

like image 296
Leif Ashley Avatar asked Jun 29 '14 14:06

Leif Ashley


2 Answers

The problem for me was that I had non-alphanumerical characters in my main target name.

I had to import it the following way (Note the special @testable annotation)

@testable import my_tutorial_app

like image 29
Kevin Goedecke Avatar answered Sep 29 '22 13:09

Kevin Goedecke


I hit the same issue today, not sure if this is only available recently - rather than using import TARGET_NAME in your test file and/or declaring your classes/methods as public, you can add your file to your Tests target via XCode's File Inspector.

Cmd + Opt + 1 to show it while in any file, and check the box under Target Membership for your Tests Target.

File Inspector - Target Membership

You may need to rebuild.... Cmd + b.

Should this be specific to my system.... I'm running Xcode 6.3 beta 1, and testing via Quick + Nimble, both installed with the latest cocoapods beta.

like image 86
Russ Matney Avatar answered Sep 29 '22 12:09

Russ Matney