DeploymentItem 属性导致测试类中的所有测试失败,并出现错误“无法创建类 [TestClass] 的实例”
当我尝试运行一组具有 DeploymentItem 属性的单元测试时,出现奇怪的错误。
单元测试解决方案有 2 个测试类,一个用于测试业务逻辑,我将其称为“a 类”(无论如何,这个类都工作正常),一个用于测试从 DeploymentItem 文件中读取数据,我将其称为“a 类” “b 级”。
当两个测试类中的 DeploymentItem 属性设置为 ANYWHERE 时,类 b 中的测试全部失败并出现错误...
无法创建类 [类 b] 的实例。错误:System.NullReferenceException:未将对象引用设置为对象的实例。
但是,如果我从两个类中完全删除 DeploymentItem 属性,则所有测试都会运行,但显然在类 b 中失败,因为没有可供读取的文件,因此所有断言都会失败。
我希望我已经充分解释了这个问题,如果没有,我应该能够在需要时澄清更多。 非常感谢任何帮助。
I'm getting a strange error when I try to run a set of unit tests where the class has a DeploymentItem attribute.
The unit testing solution has 2 test classes, one to test business logic which I'll refer to as 'class a' (this one works fine regardless) and one to test reading of data from the DeploymentItem file which I'll refer to as 'class b'.
With the DeploymentItem attribute set ANYWHERE within the two test classes, the tests in class b all fail with the error...
Unable to create instance of class [class b]. Error: System.NullReferenceException: Object reference not set to an instance of an object..
However, if I completely remove the DeploymentItem attribute from both classes, all tests run, but obviously fail in class b because there is no file to read from, therefore all asserts fail.
I hope I've explained the problem fully, if not I should be able to clarify more if required.
Very grateful for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速猜测:您是否选中了 .testrunconfig 文件中的启用部署复选框?如果没有,DeploymentItemAttribute 将不起作用。
虽然不确定它是否会给你这个例外,但值得一试。
A quick guess: Have you checked the Enable deployment checkbox in your .testrunconfig file? If not, DeploymentItemAttribute is not going to work.
Not sure whether it will give you that exception, though, but it's worth checking out.