Adding Unit and UI tests to an existing project in Xcode

Xcode

Xcode Problem Overview


Lets say I have an existing project in Xcode, and for whatever reason, did not add Unit Tests or UI Tests. Can I add the test projects to the project later in Xcode 7?

Xcode Solutions


Solution 1 - Xcode

Yes!

You can add new test targets for UI and unit tests by navigating File > New > Target > Test. When that's done, add new test cases by navigating File > New > File > Source.

Test Target

Solution 2 - Xcode

Tests are targets.

Select the project in the navigation view then Menu File > New > Target… and Test of the proper SDK.

Choose UI Testing Bundle or Unit Test Bundle.

Repeat the procedure to add the other test bundle.

Solution 3 - Xcode

Xcode add test to target

One more variant Xcode 10.2.1 using Test Navigator

  1. ⌘ Command + 6 or View -> Navigators -> Show Test Navigator
  2. Right click or + at the bottom
  3. New Unit Test Target... or New UI Test Target...

https://i.stack.imgur.com/5EDuJm.png" height="150">

Solution 4 - Xcode

Follow this steps,it works's fine

1.Select the project.

2.Targets->Click the + button->Add iOS UITesting Bundle or iOS UnitTesting Bundle.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJames ParsonsView Question on Stackoverflow
Solution 1 - XcodeChris DroukasView Answer on Stackoverflow
Solution 2 - XcodevadianView Answer on Stackoverflow
Solution 3 - XcodeyoAlex5View Answer on Stackoverflow
Solution 4 - XcodePreethaView Answer on Stackoverflow