Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 5 unit testing: starts my app

When I run my tests in XCode 5, the main window of my OS X app appears on the screen for a couple of seconds while running the tests. Why? Even if I uncomment all my tests it still opens my main window.

like image 416
dhrm Avatar asked Oct 07 '13 08:10

dhrm


People also ask

How do I run unit tests in Xcode?

⌘U will build and run all your test cases. It is the most commonly used shortcut when creating unit test cases. It is equivalent to ⌘R (build & run) while doing app development. You can use this shortcut to build your test target and run all the test cases in your test target.

Should I include tests Xcode?

You do not need to include unit tests. Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application.

What is difference between unit tests and UI test in Xcode?

The really short version is that unit tests have access to the code in your app (or whatever kind of module you are building) and UI tests do not have access to the code. A unit test only tests one single class per test.

Does Xcode run tests in parallel?

You can speed up your tests with parallel distributed testing. In this case, xcodebuild will distribute tests to each run destination by class. Each device then runs a single test class at a time.


2 Answers

You are running application test, not logic test. This means an instance of your app will be started and then run the unit tests. This allow you to perform some integration test that require your app is running.

Here is the guide to setup application test and logic test.

If you want to change it to logic test (so it run faster and don't need to start your app first):

  1. go to build settings for your unit test target
  2. search Bundle
  3. remove Bundle Loader and Test Host

enter image description here

like image 110
Bryan Chen Avatar answered Sep 19 '22 18:09

Bryan Chen


Thats right, you have to delete the "Bundle Loader" and "Test Host" from your build settings.

But you have to add the necessary implementation files to your unit test target. The necessary files are what you want to use in your unit test cases. You need to do this because in logic tests XCode wont compile the whole application. So some of your files will be missing.

This is en error message if you have left out a file:

Undefined symbols for architecture i386:   "_OBJC_CLASS_$_Module", referenced from:       objc-class-ref in Lobic Network.o       objc-class-ref in Logic_Unit.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

You can add the missing files by selecting the implementation file and bringing up the file inspector. There will be a section named "Target Membership" and there you can set the files target membership to your unit test also.

like image 23
Szasza Avatar answered Sep 20 '22 18:09

Szasza