do I need to manually add each *.m file to my unit test target when it's needed?
Asked Answered
G

3

5

I'm using Unit Testing in XCode 4. I've been adding my application *.m files to the unit test target "compile sources" as I refer to them so the unit test will build/run.

Is there a better way here?

Note - I've just tried adding the application to the unit test target "target dependencies", but this didn't seem to work (still get some build errors).

Graduation answered 27/4, 2011 at 23:11 Comment(0)
A
2

Yes, you will need to add each and every .m file you need to your unit test target.

This will include them in the target compile and link phases.

Alienor answered 27/4, 2011 at 23:15 Comment(1)
No longer required; see my answer.Whoremaster
W
8

Prior to Xcode 4, the approach you describe was necessary: An application test target had to essentially be a copy of your actual application, plus tests.

But with Xcode 4, we no longer need to do this for testing in the simulator. Instead, use a target that is a unit test bundle, and add your tests to the bundle. During testing, the application is launched, and the test bundle will be injected into and linked with the application, all at runtime.

Since it sounds like you tried this approach, let's discuss the actual errors you get.

Whoremaster answered 2/5, 2011 at 21:20 Comment(5)
Hi Jon - perhaps I'm running the tests the wrong way - what I have been doing is changing the profile to UnitTests and then hitting Command-U (test). In this case it appears my Unit Test target requires the supporting files. Was this what you'd understood re my problem?Graduation
To see how it's done in a more integrated way, create a brand new project. Be sure to select "Include Unit Tests". You'll get a single scheme that incorporates two targets: the main target and the test target. Study the Build Settings of the test target. Also study the scheme settings.Whoremaster
As it's a long way down to check all the build settings, I just want to say that I only had to change/add stuff in "Linking" => BundleLoader and "Unit Testing" => Test Host, to get it working. Hope this could help someone to not have to check each setting there. PS: I think this should be the accepted answer!Cheiro
It's true that everything builds and runs correctly, but autocomplete doesn't work when you do this. How do you fix that?Golconda
Something's still wrong if your autocorrect isn't working.Whoremaster
A
2

Yes, you will need to add each and every .m file you need to your unit test target.

This will include them in the target compile and link phases.

Alienor answered 27/4, 2011 at 23:15 Comment(1)
No longer required; see my answer.Whoremaster
K
0

if testTarget was created based om SWIFT language in Obj-C project

It would be enough to make scheme of testTrget but such away: product -> scheme -> edit scheme -> Build tab: checked only Test nothing more.

IMPORTANT: You should not include each .m file into test target Just to add headers into testTarget-Bridging-Header.h

Note: if you will CHECK more in scheme or INCLUDE .m file into testTarget you can get headers conflicts

Krill answered 17/10, 2014 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.