How to Change Compilation Dynamically When Running Xcode Tests

Asked 1 years ago, Updated 1 years ago, 66 views

To test the API in Xcode, we are trying to use NLTHTTPStubServer as a dummy server.
I tried the preprocessor macro to change the URL of the development environment and the URL in the test, but it didn't work.

What I've done
Duplicate "Debug" and create "Debug_copy"
2. Set "DEVELOPMENT_ENV" to "Debug_copy" preprocessor macro
3. Change Test Debug to Debug_copy from Schema Settings
4. Set production code to change URL constants with or without DEVELOPMENT_ENV definition
5. Running the test will cause the build to fail.

The details of the error are as follows:
ld —library not found for-lAFNetworking
clang:error:linker command failed with exit code 1 (use-v to see invocation)

I don't know why the error occurs because I haven't changed anything other than defining the macro.
If anyone knows the cause and how to dynamically change the compilation when running the test, please let me know.
The purpose is to set the URL (string) for the test during the test.

ios xcode

2022-09-30 19:48

2 Answers

Do you happen to use CocoaPods?
Otherwise, ignore this answer.

If you use CocoaPods, I think you can solve this problem by using the one for Debug_copy when linking the libraries on the Pods side.

*The xxxx part is the project name of the application


2022-09-30 19:48

Hello
I use the same method of switching behavior using macros on a daily basis.

I don't know the details, but I will answer because it might be a hint.
The original Debug has been successfully built, so why don't you try setting the DEVELOPMENT_ENV macro on the original Debug?

If that works, there should be something missing in Debug_copy's settings.
I think you can find it if you check Build Settings to kill the cold.
Is it related to the search path as it seems that the library cannot be found?


2022-09-30 19:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.