yuvaraju
yuvaraju

Reputation: 167

unit test cases for Core Data in swift4

How to write unit test cases for core data in swift4?

I am new to writing unit test cases, to understand core data unit test cases, I referred this link.

But while running unit test cases, If I select unit test cases at target membership (in "appDelegate" and "ToDoStorgeManager" files) then I am running unit test cases, it showing errors like "One of the two will be used. Which one is undefined." at same time app got crush. If I unselected unit test then its working fine as we expected.

Please look into below pictures at "Target Membership" section to get clarity about my question.

when I am writing unit test cases for independent classes, I am not facing above issue.But In core data I am facing issue with check and uncheck for unit cases in Target Membership.

Please help me to understand the above scenario.

enter image description here enter image description here

Upvotes: 0

Views: 270

Answers (1)

ezaji
ezaji

Reputation: 304

When you turn on check box in Target Membership section you also add this file as Compile Source for unit test target:

Check box for ViewController is off

Check box for ViewController is off

Check box for ViewController is on

Check box for ViewController is on

All unit tests have target dependency because their role is to test classes from this dependency that contains ViewController as Compile Source also. Compiler doesn't know which reference to this file (from unit test or from target dependency) should be compiled. It is known as name collision.

You can access directly to classes from dependency target without adding one to unit test target.

Upvotes: 1

Related Questions