使用特定的 Visual Studio 项目构建配置来运行单元测试

2024-01-15

我的公司已经拥有 Team Foundation Server 作为持续集成平台。但是,我想要设置的是开发人员可以在自己的开发计算机上运行的构建配置。

假设我有一个包含 .NET C# 类库项目(我将其称为库项目)的 Visual Studio 解决方案。它还包含另一个项目,其中包含库项目的单元测试类(我将其称为测试项目)。

我在每个项目和解决方案级别都有正常的调试和发布构建配置。对于这两种配置,我将其设置为仅构建库项目(因此不会构建测试项目)。

我想做的是设置 2 个新的构建配置,称为“调试与测试”和“发布与测试”。它们分别与调试和发布相同,但我需要它们具有以下额外功能:

  1. 构建测试项目。
  2. 运行测试项目中的所有测试用例。
  3. 对库项目运行代码分析。
  4. 生成测试和代码分析报告。
  5. 将报告保存在特定位置。

执行第 1 项很容易。但是,我不知道如何执行第 2 至 5 项。有人能指出我正确的方向吗?

任何帮助将不胜感激。 TIA


您将需要编写自定义 MS 构建代码,我已经做了一些类似的任务,如下所示:

  • 从 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="--------------------------------&nbsp; Running Unit Tests for category 1 only--------------------------------"&nbsp; />
 <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-include-get-latest-deploy-db-run-test-check-in/ http://mohamedradwan.wordpress.com/2010/11/13/automate-the-best-practice-for-check-in-including-get-latest-deploy-db-run-test-check-in/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用特定的 Visual Studio 项目构建配置来运行单元测试 的相关文章