IOS Swift unit test leads to unresolved identifier

Simple function for quick 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 the classes from my module. In addition, although I may have messed up something in the project, but NONE from my sample projects will allow me to use module classes.

It seems like it should work, but it may have broken in beta 2.

EDIT: fixed IDE did not select parameter name checking. Xcode seems to be still a bit lower

+6
source share
4 answers

Today I am facing the same problem, not sure if this is available only recently - instead of using import TARGET_NAME in the test file and / or declaring your classes / methods as public , you can add your file to your target tests through the XCode File Inspector .

Cmd + Opt + 1 to display it in any file, and check the Target Membership checkbox for your target.

File Inspector - Target Membership

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

If this is specific to my system .... I am running Xcode 6.3 beta 1 and testing through Quick + Nimble, both installed with the latest beta version of cocoapods.

+13
source

It seems that in Xcode 6 Beta 4 you need to declare public classes and methods as "public". Example:

 public class Device { public init(...) { } public func myMethod(...) { } } 

Now they are available from the quick test class.

+7
source

The problem for me was that I did not have alphanumeric characters in my primary target name.

I had to import it as follows (note the special @testable annotation )

@testable import my_tutorial_app

+5
source

Importing the target name into Swift will solve the problem.

0
source

Source: https://habr.com/ru/post/971497/


All Articles