I'm fairly inexperienced in iOS. I wanted to write Unit Test for my Cocoapods Project.
My ViewControllers that I want to test are in Pods. When I want to write a unit test, I already receive an error message with
import MyApplication
which says
No such module 'MyApplication'
Note that I used "MyApplication" only as a substitute for orginal name I crossed out in red in the picture.
What is the issue?
EDIT:
code of my test class:
import UIKit
import XCTest
import Pods_MyApplication_Example
@testable import Pods_MyApplication
class Tests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
XCTAssert(true, "Pass")
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure() {
// Put the code you want to measure the time of here.
}
}
}
To create a test target, on the test navigator, I click on the '+' and then choose 'New Unit Test Target'
I am sorry if there are any information missing. I will add those if there are any!
EDIT2: Changed picture which might provide more information
You must use @testable import
to import your app's module for unit testing. You have to supply the name of your application target, Pods_MyApplication_Example, not the name of the project. In your example it will look like the following:
@testable import Pods_MyApplication_Example
And remove the import statement that imports the app target.