简体   繁体   English

swift4中Core Data的单元测试用例

[英]unit test cases for Core Data in swift4

How to write unit test cases for core data in swift4? 如何在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." 但是在运行单元测试用例时,如果我以目标成员身份(在“ appDelegate”和“ ToDoStorgeManager”文件中)选择单元测试用例,那么我正在运行单元测试用例,它将显示诸如“将使用两个之一。未定义。” 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. 请帮助我了解上述情况。

在此处输入图片说明 在此处输入图片说明

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 ViewController的复选框处于关闭状态

ViewController的复选框处于关闭状态

Check box for ViewController is on ViewController的复选框处于启用状态

ViewController的复选框处于启用状态

All unit tests have target dependency because their role is to test classes from this dependency that contains ViewController as Compile Source also. 所有单元测试都具有目标依赖关系,因为它们的作用是从包含ViewController作为编译源的依赖关系中测试类。 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. 您可以直接从依赖关系目标访问类,而无需将其添加到单元测试目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM