Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding test target to an existing project is not working

I need to add test cases to an existing project, so I tried adding a new test target via

  1. File -> New -> Target -> Cocoa Touch Testing Bundle
  2. From the test navigator filter bar.

Even after adding, the target is not getting listed in the test filter bar. May be because of this issue, Product -> Test option is diabled in my project. Also I could see some differnce between the build setting in my project and another sample project I started in Xcode 6.1 in which Product -> Test option is enabled and everything working fine for Test cases.

Please find the build settings screen shots. My Project Build settingsSample Project's Build settings

Any help is appreciated.

like image 616
Kannan Prasad Avatar asked Apr 22 '15 06:04

Kannan Prasad


People also ask

How do I add unit tests to an existing Xcode project?

To add a unit test target to an existing Xcode project, choose File > New > Target. Select your app platform (iOS, macOS, watchOS, tvOS) from the top of the New Target Assistant. Select the Unit Testing Bundle target from the list of targets.

Where is project target in Xcode?

Select your project in Xcode now in the general tab you will be able to see the targets of your project. It usually comprises TestCases or if your app supports today's extension it also appears as a target, these are some usually visible targets in any app.


1 Answers

I had this exact problem. It turns out my existing project was creating my Cocoa Touch Testing Bundle with the .app extension when it should've been a .xctest extension.

You can fix this by going to your test target you created. Build Settings > Wrapper Extension and changing it from app to xctest.

You may have to restart Xcode after this change to select your test target.

UPDATE: I found out the reason the Testing Bundle was becoming a .app extension in the first place. I had to go to the main project Wrapper Extension and make sure it was blank instead of .app. Apparently that was forcing all targets to become .app extension as well.

like image 92
teradyl Avatar answered Sep 28 '22 11:09

teradyl