使用特定的 Visual Studio 项目构建配置来运行单元测试 [英] Using specific Visual Studio Project Build configuration for running unit tests
问题描述
我的公司已经有一个 Team Foundation Server 作为持续集成平台.但是,我希望设置的是开发人员可以在他们自己的开发机器上运行的构建配置.
My company already has a Team Foundation Server as a Continuous Integration platform. However, what I am looking to setup is a build configuration that a developer can run on their own development machine.
假设我有一个 Visual Studio 解决方案,其中包含一个 .NET C# 类库项目(我将其称为库项目).它还包含另一个项目,其中包含库项目的单元测试类(我将其称为测试项目).
Let's say I have a Visual Studio solution that contains a .NET C# Class Library project (I'll call this the Library Project). It also contains another project containing the Unit Testing classes for Library Project (I'll call this the Testing Project).
我有每个项目和解决方案级别的正常调试和发布构建配置.对于这两种配置,我已将其设置为仅构建库项目(因此不会构建测试项目).
I have the normal Debug and Release build configurations for each project and at the solution level. For both of these configurations, I have set it to only build the Library Project (so Testing Project does not get built).
我想做的是设置 2 个新的构建配置,称为 Debug With Testing 和 Release With Testing.它们分别与 Debug 和 Release 相同,但我需要它们具有以下额外功能:
What I would like to do is set up 2 new build configurations called Debug With Testing and Release With Testing. They will each be the same as the Debug and Release, respectively but I need them to have the following extra features:
- 构建测试项目.
- 运行测试项目中的所有测试用例.
- 对库项目运行代码分析.
- 生成用于测试和代码分析的报告.
- 将报告保存在特定位置.
做第 1 项很容易.但是,我不知道如何做第 2 到 5 项.有人能指出我正确的方向吗?
Doing item 1 is easy. However, I can't figure out how to do items 2 to 5. Can anyone point me in the right direction?
任何帮助将不胜感激.TIA
Any help will be greatly appreciated. TIA
推荐答案
您将需要编写自定义的 MS 构建代码,我已经做了一些类似的任务,如下所示:
You will need to write custom MS build code, I already do some similar task as the following:
- 从 TFS 获取最新更改
- 构建包含所有项目的解决方案
- 在本地部署主数据库
- 在本地部署测试数据库,其中保存了测试中使用的测试数据数据驱动测试
- 运行健全性测试或 BVT(构建验证测试)属于第 1 类(测试 DB 和代码之间的集成)
- 签入待处理的更改
并听到这个任务的代码
<Target Name="GetLatestFromTFS2010" AfterTargets="build" >
<Message Importance="high" Text ="start GetLatest for the project "></Message>
<Exec Command='"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" get $/AutoDBand/AutomateDatabaseAndTest/AutomateDatabaseAndTest /recursive /login:YourUsername,YourPassword' ContinueOnError='false'/>
</Target>
<!--===========Deploy Database============-->
<Target Name="DeployDatabase" AfterTargets="GetLatestFromTFS2010" Condition="'$(Configuration)' == 'DebugForCheck-in'">
<Message Importance="high" Text="-------------------------------- Deploying Database according to the connection string -------------------------------- " />
<Message Importance="high" Text=" "/>
<MSBuild Projects="..\DB\DB.dbproj" Targets="Build;Deploy" />
</Target>
<!--============Run the Test==================-->
<Target Name="UnitTests" AfterTargets="DeployDatabase" Condition="'$(Configuration)' == 'DebugForCheck-in'">
<Message Importance="high" Text="-------------------------------- Running Unit Tests for category 1 only--------------------------------" />
<Message Importance="high" Text=" "/>
<Exec Command='"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /testcontainer:"..\BLTest\bin\Debug\BLTest.dll" /category:cat1' />
</Target>
<Target Name="Chekin-pendingChange" AfterTargets="UnitTests" >
<Message Importance="high" Text ="-------------------------------- start Check-in process-------------------------------- "></Message>
<Message Importance="high" Text=" "/>
<Exec Command='"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" checkin $/AutoDBand/AutomateDatabaseAndTest/AutomateDatabaseAndTest /recursive /login:YourUsername,YourPassword' ContinueOnError='false'/>
</Target>
有关更多信息,您可以查看带有源代码的这篇文章http://mohamedradwan.wordpress.com/2010/11/13/automate-the-best-practice-for-check-in-including-get-latest-deploy-db-运行测试签入/
For more information you can see this article with source code http://mohamedradwan.wordpress.com/2010/11/13/automate-the-best-practice-for-check-in-including-get-latest-deploy-db-run-test-check-in/
这篇关于使用特定的 Visual Studio 项目构建配置来运行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!