Using specific Visual Studio Project Build configuration for running unit tests

╄→гoц情女王★ 提交于 2021-02-19 06:54:04

问题


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.

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).

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. Builds the Testing Project.
  2. Run all test cases in the Testing Project.
  3. Run Code Analysis on Library Project.
  4. Generate report for testing and code analysis.
  5. Save report in a specific location.

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?

Any help will be greatly appreciated. TIA


回答1:


You will need to write custom MS build code, I already do some similar task as the following:

  • Get the latest change from TFS
  • Build the solution including all projects
  • Deploy the Main Database locally
  • Deploy the Test Database locally which hold the test data used in the data driven test
  • Run the sanity test or BVT (Build Verification Test) which has belong to category 1 (Test the integration between DB and code)
  • Check-in the pending change

And hear the code of this tasks

<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>

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/




回答2:


Have a look at something like:

  • TeamCity
  • Jenkins
  • Team Foundation Server

all are Continous Integration Servers, which are good in doing the jobs you like to have done.



来源:https://stackoverflow.com/questions/7331570/using-specific-visual-studio-project-build-configuration-for-running-unit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!