开发者

Can I get automated MSTest testing with VS2010?

I would like to have MSTest (honestly, I'd take whatever at this point) run my tests post-build, and then if any tests fail, produce the standard file(lineno): message output that Visual Studio recognizes and allows me to go straight to the failure point.

Or, if possible, then after a successful build I'd like the "Run All Tests in Solution" Visual Studio command to fire automatically.

开发者_Python百科As far as I can tell, this isn't possible. The commandline version of MSTest does not produce correctly formatted output (and as far as I can tell, neither does NUnit or xUnit), so when I add MSTest to my project's Post Build, I still have to scroll around, looking for the one that failed. The in-IDE version works ok, as long as I remember to hit Ctrl-R,A when the build finishes.


You can get what you are looking for by making a custom target in your project file instead of using the pre-baked PostBuild target. Add something like this right into your project file, editing it as XML,

<Target Name="RunUnitTests"
  AfterTargets="CoreBuild">
  <Exec
    Command="mstest /testcontainer:$(OutDir)\PathToUnitTests\UnitTests.dll"
    CustomErrorRegularExpression="^Failed"
    />
</Target>

You'll need to properly set the path to your test assembly or whatever other method you are using (test config file etc.), and you may need to tweak the regex, going from memory here...

This will run mstest similar to how you are probably doing in the PostBuild, but adds in the ability for MSBuild (which is what drives the C# build system) to detect output strings that it should consider errors. There is a similar parameter for a CustomWarningRegularExpression also.

If you want to share this among multiple projects, look up "MSBuild Imports"


I've switched to xUnit, and with a minor change to their MSBuild unit test runner, I get what I want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜