将 Microsoft Pex 与 Prism 复合应用程序结合使用

发布于 2024-10-16 07:51:31 字数 315 浏览 6 评论 0原文

我正在 Prism 复合应用程序中实施单元测试,并尝试实施 Microsoft Pex (http: //research.microsoft.com/en-us/projects/pex/)来加快此任务的速度。 但我遇到了很多与 Prism 相关的麻烦。尽管使用 Moles 来存根 Prism 实现,但我在执行过程中遇到了很多错误和问题。

有人已经成功地将 Pex 与 Prism 应用程序一起使用了吗?

预先感谢您的回答

I'm implementing unit testing in my Prism composite application and trying to implement Microsoft Pex (http://research.microsoft.com/en-us/projects/pex/) to speed up this task.
But I'm experiencing a lot of troubles linked to Prism. Despite the use of Moles to stub Prism implementations, I have a lot of errors and problems doing it.

Has someone already successfully used Pex with a Prism application?

Thanks in advance for your answers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

避讳 2024-10-23 07:51:31

经过几个小时的努力,我终于成功地在我想要的项目中实现了测试。
以下是我在 Prism 复合应用程序中使用 Pex 和 Moles 的经验的一些详细信息(我也使用 CodeContracts 并且我建议使用它,但这在这里没有发生)。

  • Pex 和 Moles 主要有两件事比较敏感:.Net 框架类和接口,以及 Prism 类和接口。由于其低级别(系统)和依赖注入(Prism),它们不容易检测。
  • 我做的第一件事是在我的项目上运行第一次 Pex 以使错误出现。在那里,我发现了一个我要求 Pex 生成的成功测试。它会自动创建带有 Pex 引用的测试项目。
  • 在那里,我确定了哪些类和接口必须被存根:它主要涉及 Prism 接口,如 IEventAggregator 和 IRegionManager。这些接口有实现并且可以被 Moles 存根。所需要做的就是右键单击 Prism 参考(在项目参考中),然后单击“为 Prism 添加摩尔”。自动生成包含所有 Prism 类存根的程序集,由 Pex 在下次探索时自动使用。 小心使用此工具。我的第一反应是“摩尔”一切(Prism、系统、依赖项......)。这是测试项目的死亡。我不知道如何抑制鼹鼠的聚集。所以当它完成时,它就完成了!
  • 我建议一点一点地“摩尔”依赖关系,并在做之前三思。有时,由于底层参数实例化错误,Pex 无法创建对象,从而导致 objecg 创建失败(Pex 报告没有显示缺乏实现和较低级别错误之间的区别。它总是说:“< em>MyClass 对象无法创建”并建议创建一个工厂)
  • 我为无法被 Moles 存根的类创建了工厂。特别是,它不适用于使用事件聚合器(继承自 CompositionPresentationEvent)的事件。
  • 要有耐心并解决。我发现 Pex 仍处于试验阶段并且“没有回头路”。解决反叛错误消息的最佳方法是删除测试项目并重新开始 pex 探索。

如果有人可以帮助我回答并提供更多细节和更正,那将非常受欢迎!

After hours of struggle, I finally managed to implement tests in the project I wanted.
Here are some details about my experience of Pex and Moles (I also use CodeContracts and I advise it, but this has no incidence here) with a Prism composite application.

  • Mainly two things are touchy with Pex and Moles: .Net framework classes and interfaces, and Prism classes and interfaces. They are not easy to instrument because of their low-levelness (system) and the dependency injection (Prism).
  • The first thing I did was running a first time Pex on my project to make errors appear. There, I found a successful test that I asked Pex to generate. It automatically creates the test project with Pex references.
  • There, I identified which classes and interfaces had to be stubbed: It concerns mainly Prism interfaces like IEventAggregator and IRegionManager. These interfaces have implementations and can be stubbed by Moles. All needed is right click in the Prism reference (in project References) and click "Add moles for Prism". Auto-generate an assembly containing stubs for all Prism classes, automatically used by Pex at the next exploration. Be careful with this tool. My first reaction was to "moles" everything (Prism, System, dependencies..). This is death for the test project. I didn't find out how to suppress moles assemblies. So when it's done, it's done!
  • I advise to "mole" dependencies part by part, and to think before doing it. Sometimes an object cannot be created by Pex because of an underlying parameter bad instanciated, causing objecg creation to fail (Pex report doesn't show the difference between a lack of implementation and an error in a lower-level. It always says: "MyClass object couldn't be created" and suggest to create a factory)
  • I created factories for classes that couldn't be stubbed by Moles. Especially, it doesn't work for events working with event aggregator (inheriting from CompositionPresentationEvent).
  • Be patient and resolved. I find Pex still experimental and "no-way-back". Best way to solve rebellious error messages was to delete the test project and to start over with pex exploration.

If someone can help my answer and give some more details and correction, it would be more than welcome!

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