98

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?

Chris Droukas
  • 3,196
  • 1
  • 23
  • 26
James Parsons
  • 6,097
  • 12
  • 68
  • 108

4 Answers4

145

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

Chris Droukas
  • 3,196
  • 1
  • 23
  • 26
  • 3
    If you are using C files with your Swift Unit Tests you may also need to point your new Target to the Bridging Header file & ensure any Header files locations are known. You access both settings via the /Build Settings against the Target. – rustyMagnet Mar 05 '19 at 16:06
20

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.

vadian
  • 274,689
  • 30
  • 353
  • 361
13

Xcode add a test to a 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...
yoAlex5
  • 29,217
  • 8
  • 193
  • 205
6

Follow this steps,it works's fine

1.Select the project.

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

Preetha
  • 753
  • 9
  • 12