简体   繁体   English

从VS2008内部运行单元测试与在命令行上使用mstest

[英]Running unit tests from within VS2008 vs using mstest on the command line

I have recently encountered some inconsistencies in running unit tests inside VS2008 vs running the same unit tests with mstest on the command line. 我最近在VS2008内部运行单元测试与在命令行上使用mstest运行相同的单元测试时遇到了一些不一致之处。

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. 我有许多针对同一DataSource运行的数据驱动的单元测试。 I also like experimenting with PostSharp. 我也喜欢尝试PostSharp。 So, I have written a PostSharp aspect - TestDataSource - which I apply to a unit test type, not the unit test methods. 因此,我编写了PostSharp方面TestDataSource我将其应用于单元测试类型,而不是单元测试方法。 When the type is built, this aspect instructs PostSharp to attach the DataSource attribute to each and every unit test method in the type. 构建类型时,此方面将指示PostSharp将DataSource属性附加到类型中的每个单元测试方法。

Examining the built assembly in Reflector shows that each test method is indeed attributed with the correct DataSource attribute. 在Reflector中检查生成的程序集可以发现,每个测试方法的确具有正确的DataSource属性。 Running the tests with mstest on the command line behaves as expected - each test is run against the specified data source. 在命令行上使用mstest运行测试的行为符合预期-每个测试都针对指定的数据源运行。

However, running exactly the same unit tests in VS2008 fails to find the data source. 但是,在VS2008中运行完全相同的单元测试无法找到数据源。 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. 好像VS2008忽略了生成的程序集并查看了源代码,这当然似乎不是数据驱动的测试,因为在生成过程中注入了DataSource属性。

There is no problem with deployed items. 部署的项目没有问题。 Attaching the DataSource manually to the tests makes VS2008 run them happily. DataSource手动附加到测试可以使VS2008轻松地运行它们。

Any ideas? 有任何想法吗?

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)? 是预期的(在bin \\ Debug中)吗? If you open this file using Reflector when the debugger is running, do you see PostSharp stuff inside? 如果在调试器运行时使用Reflector打开此文件,您是否在其中看到PostSharp的内容?

What's strange is that a part of PostSharp unit tests are written for MSTest and they run from Visual Studio without problem... 奇怪的是,PostSharp单元测试的一部分是为MSTest编写的,它们可以从Visual Studio运行而不会出现问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM