swift Xcode 单元测试:无法转换类型“人"的值;到预期的参数类型“人" [英] swift Xcode unit test: Cannot convert value of type "Person" to expected argument type "Person"

查看:24
本文介绍了swift Xcode 单元测试:无法转换类型“人"的值;到预期的参数类型“人"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个单元测试类来测试我的自定义类.当我尝试使用自定义对象作为输入变量调用自定义类中的方法时,我得到:'无法将Person"类型的值转换为预期的参数类型Person".Person"是从 NSManagedObject 继承的类,输入对象是从那里创建的.我对采用其他值类型的其他方法没有问题.该方法工作正常.测试班是唯一抱怨这一点的班级.这是错误还是限制?有什么建议我可以深入研究这个问题吗?

I am trying to write a unit test class to test my custom classes. When I am trying to call a method in the custom class with a custom object as the input variable, I got: 'Cannot convert value of type "Person" to expected argument type "Person". "Person" is the class, inherited from NSManagedObject, where the input object was created from. I have no problem with other methods taking other value type. The method works fine. The test class is the only one complains this. Is it a bug or limitation? Any suggestion I can dig deeper on this issue?

推荐答案

我之前遇到过这个问题.事实证明,被测系统(在我的例子中是调用对象的服务;对于您的示例,可能是 PersonService)没有测试项目的 Target 成员资格.我只是点击了 .swift 文件,并确保主项目和测试项目都被选中.

I was running into this issue earlier. It turns out that the system under test (in my case it was a service calling the object; a PersonService for your example, perhaps) did not have Target membership to the test project. I just clicked the .swift file, and made sure both the main project and test project were checked.

希望这会有所帮助!

这篇关于swift Xcode 单元测试:无法转换类型“人"的值;到预期的参数类型“人"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆