DeploymentItem 属性导致测试类中的所有测试失败,并出现错误“无法创建类 [TestClass] 的实例”

发布于 2024-08-16 11:56:42 字数 446 浏览 1 评论 0原文

当我尝试运行一组具有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待"谢繁草 2024-08-23 11:56:42

快速猜测:您是否选中了 .testrunco​​nfig 文件中的启用部署复选框?如果没有,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文