Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 905 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Xcode Test not detect my class

#1
I have class named Meal.swift in my project and a unit test

func testMealInitialization() {
// Success case.
let potentialItem = Meal(name: "Newest meal", photo: nil, rating: 5)
XCTAssertNotNil(potentialItem)

// Failure cases.
let noName = Meal(name: "", photo: nil, rating: 0)
XCTAssertNil(noName, "Empty name is invalid")

}

But the problem is that: **Use of unresolved identifier "Meal"**
Reply

#2
Xcode 7 adds the `@testable import` statement to simplify unit testing. At the top of your unit test class files, add the following statement:

@testable import MyApp

Where **MyApp** is the name of your iOS app. Now the unit test target should be able to find the classes in your app and run the tests. If you get link errors saying that Xcode cannot find your app classes, make sure the Product Module Name build setting's value matches the name you use in the `@testable import` statement, **MyApp** in this example.

If `@testable import` does not work for you, a workaround is to make your app classes members of the unit test target. You can set the target membership of a file in Xcode using the file inspector.
Reply

#3
In my case, I got error only in the new class I've just made, and it makes me confuse. So, it works by select **Unit Test** target under **class membership** of my new class. Or delete the class, make new class again, then select **Unit Test Target** in that new class.
Reply

#4
Click on your Meal class. Then on the right side you'll see 'Target Membership' section. Select your test project.
(Xcode 7)
Voilà.
Reply

#5
I also encountered this issue, what worked for me is reloading my test file and retyping the

@testable import FoodTracker

then at that point, it detected my FoodTracker classes (Meal class) and errors are gone.
Reply

#6
`@testable import MyApp` should work fine. Just remember to set appropriate configurations within `Debug` for your `UITest` target.

[![enter image description here][1]][1]


[1]:
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through