I'm trying to create my first XCTestCase within my existing iOS+Mac project. I created a new test class, and I see that it created a new test target for me in my project, but the new scheme has none of the linked libraries and source code files from my existing target. It just shared the scheme from the existing target, but none of the project details. I don't want to go add each and every source file and framework library into the new test target. Is there a way to simply create a new test target that is a clone of an existing target? Or add all source files into my target without it being
Asked
Active
Viewed 3,146 times
0
-
File > New > Target > iOS > Other > Cocoa Touch Unit Testing Bundle – matt Apr 04 '14 at 18:13
-
That does the same thing: created a new test bundle with the same scheme as the main target, but doesn't include any of the source files or linked libraries from the main target. – Z S Apr 04 '14 at 18:30
-
Are you `#importing` the relevant headers? – Abizern Apr 04 '14 at 18:36
-
It's not clear to me what else you're after. This gives you a correctly set up test target. – matt Apr 04 '14 at 18:37
-
It sets up a test target just fine, but if I look in Target -> Build Phases -> Compile Sources, it has 2,3 files in it. My normal target has over 300. I want the test target to be created with all the compile sources listed there so I don't have to add them one-by-one. – Z S Apr 04 '14 at 18:52
-
1You don't need to add files to the test _target_ because the test target depends on the app target. Your _code_ can thus include anything it needs to. – matt Apr 05 '14 at 01:23
2 Answers
3
When set up correctly, the test bundle is linked against your app. You shouldn't put any production code into your test target, only test code.

Jon Reid
- 20,545
- 2
- 64
- 95
0
I was probably doing something wrong in how I setup the test target. You can create a new test Target, (from New -> Target -> Unit Testing Bundle), set it up from an existing target, and it should build and link just fine, and you can import any existing files into the test class.

Z S
- 7,039
- 12
- 53
- 105