Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Unit Tests to an already existing project?

When you create an XCode 4 project, it asks you if you want to include unit testing. But how do you add it to a project that's been created without them?

I started a project with Unit Tests to try to figure it out, and it looks like the only difference between it and my existing project are the Test.h and Test.m files in the new project.

But when I move them into my old project and try to build, it says no such file or directory: SenTestingKit/SenTestingKit.h. That looks like a framework to me, but if I go to build phases and try to add the framework, there isn't one available called SenTestingKit :( And the new project only links the usual suspects: UIKit, CoreGraphics, and Foundation, but no SenTestingKit.

like image 338
Randall Avatar asked Jul 28 '11 21:07

Randall


People also ask

Can unit testing be successfully added into an existing production project if so how and is it worth it?

You can be a very productive programmer by "conventional" standards and still struggle to write unit tests in a way that scales in a larger project. Also, and specifically for your situation, adding unit tests to an existing code base that has no tests is also a specialized skill in itself.

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.

How would you implement JUnit for an existing project?

To use JUnit you must create a separate . java file in your project that will test one of your existing classes. In the Package Explorer area on the left side of the Eclipse window, right-click the class you want to test and click New → JUnit Test Case. A dialog box will pop up to help you create your test case.


1 Answers

Answer updated for Xcode 10.2.

Glad you asked this question — it's never too late to add tests to a project!

  1. Open your targets panel by selecting your project in the navigator,
  2. Click the + button that's at the bottom of the target list,
  3. Select iOS Unit Testing Bundle under Test section in iOS tab,
  4. Provide the required information and click Done.

It's that simple. Xcode will generate a target, some boilerplate files such as Info.plist and an initial test case file for you. Happy testing!

like image 152
akashivskyy Avatar answered Sep 19 '22 19:09

akashivskyy