iOS

When the application name is changed for each configuration, make it possible to use the module name of UnitTest’s testable with a common name

When the application name is changed for each configuration, make it possible to use the module name of UnitTest’s testable with a common name

When I was working today, I got an error in the title for the first time in a while, so I’ll make a note of how to deal with it for a memorandum!

As I did in the article below, change the Scheme and Configuration settings in the Xcode project, create an application for each server connection destination, create a Configuration for Test, and name each application After changing , if you run UnitTest, you will get an error at the place written in the test code like @testable import HomeNote.

What to do when the error "Could not find test host for ~" appears in UnitTest on iOSSummary of what to do when the error "Could not find test host for ~" appears in UnitTest on iOS...

I think that error is telling you to use the Module name for each Configuration you build.
But if you do it that way, I think you’ll have to write it like this:

import XCTest
#if DEVELOP_DEBUG
@testable import HomeNote
#elseif DEVELOP_TEST
@testable import HomeNote-DT
...
#endif

It’s not practical to write a file for each test like this.
So let’s make it common to write like @testable import HomeNote.

To do so, change the PRODUCT MODULE NAME setting below.

  1. Select Target -> Build Settings for your app
  2. Search `PRODUCT MODULE NAME`

So you probably have a different name for each Configuration.
Set this to the same name as your Target.
Actually, I think it can be achieved by setting the value of $(TARGET_NAME).

Now you can import with the Target name of the application as follows!

import XCTest
@testable import HomeNote
+1

COMMENT

Your email address will not be published. Required fields are marked *

CAPTCHA