Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Unit Testing: Class is implemented in both

I'm building an iOS 9 App with Swift 2 and Xcode 7.

My app runs fine when deploying it to my phone but when I run any unit test, I get the following error message for a lot of classes:

Class _TtC5<AppName>19<ClassName> is implemented in both /Users/<Username>/Library/Developer/CoreSimulator/Devices/<UUID>/data/Containers/Bundle/Application/<UUID</<AppName>.app/<AppName> and /Users/<Username>/<Path/To/Workspace>/DerivedData/<AppName>/Build/Products/Debug-iphonesimulator/<AppName>.xctest/<AppName>. One of the two will be used. Which one is undefined.

Any ideas?

like image 797
fancy Avatar asked Oct 14 '15 14:10

fancy


People also ask

How is unit testing implemented?

A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.

What is unit testing in iOS?

A unit test is a function you write that tests something about your app. A good unit test is small. It tests just one thing in isolation. For example, if your app adds up the total amount of time your user spent doing something, you might write a test to check if this total is correct.

How is unit testing implemented in C?

Define the function within the unit test file itself, probably at the top of the file. If it is a C function being called by C code, place it within the extern "C" {} section. As a last resort, one can compile out the function calls and implementations using a define for unit tests. e.g. #if !

Can a unit test test multiple classes?

A test can exercise methods from three objects and still be a unit test. Some may claim that's integration but three lines of code are just as "integrated" so that's not really a thing. Method and object boundaries don't present any significant barrier to testing.


1 Answers

Only add the test class to your test target and none of the iPhone app classes. Then simply import your app name as a module on top of your test class to get access to all app classes.

@testable import MyAppName
like image 162
Mundi Avatar answered Nov 14 '22 23:11

Mundi