在 VS2008 中运行单元测试与在命令行上使用 mstest
我最近在 VS2008 中运行单元测试与在命令行上使用 mstest 运行相同的单元测试时遇到了一些不一致的情况。
我的场景有点高级,所以我可能遇到了一些困难。 我有许多针对同一数据源运行的数据驱动单元测试。 我也喜欢尝试 PostSharp。 因此,我编写了一个 PostSharp 方面 - TestDataSource
- 我将其应用于单元测试类型,而不是单元测试方法。 构建类型时,此方面指示 PostSharp 将 DataSource 属性附加到类型中的每个单元测试方法。
检查 Reflector 中构建的程序集表明,每个测试方法确实都具有正确的 DataSource
属性。 在命令行上使用 mstest 运行测试的行为符合预期 - 每个测试都针对指定的数据源运行。
然而,在VS2008中运行完全相同的单元测试却无法找到数据源。 就好像 VS2008 忽略构建的程序集并查看源代码一样,当然,这似乎不是数据驱动的测试,因为 DataSource
属性是在构建期间注入的。
部署的项目没有问题。 手动将 DataSource
附加到测试中可以使 VS2008 愉快地运行它们。
有任何想法吗?
I have recently encountered some inconsistencies in running unit tests inside VS2008 vs running the same unit tests with mstest on the command line.
My scenario is a bit advanced, so I have probably hit some corners. I have many data driven unit tests running against the same DataSource. I also like experimenting with PostSharp. So, I have written a PostSharp aspect - TestDataSource
- which I apply to a unit test type, not the unit test methods. When the type is built, this aspect instructs PostSharp to attach the DataSource
attribute to each and every unit test method in the type.
Examining the built assembly in Reflector shows that each test method is indeed attributed with the correct DataSource
attribute. Running the tests with mstest on the command line behaves as expected - each test is run against the specified data source.
However, running exactly the same unit tests in VS2008 fails to find the data source. It is as though VS2008 ignores the built assembly and looks at the source code, which, of course, does not appear to be a data driven test, because the DataSource
attribute is injected during the build.
There is no problem with deployed items. Attaching the DataSource
manually to the tests makes VS2008 run them happily.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在测试中放置断点并检查加载的模块列表,您应该看到哪个是您正在调试的程序集的确切路径。 它是预期的吗(在 bin\Debug 中)? 如果在调试器运行时使用 Reflector 打开此文件,您会看到里面的 PostSharp 内容吗?
奇怪的是,PostSharp 单元测试的一部分是为 MSTest 编写的,并且它们从 Visual Studio 运行没有问题......
If you put a breakpoint in your test and inspect the list of loaded modules, you should see which is the exact path of the assembly you are debugging. Is it the expected one (in bin\Debug)? If you open this file using Reflector when the debugger is running, do you see PostSharp stuff inside?
What's strange is that a part of PostSharp unit tests are written for MSTest and they run from Visual Studio without problem...