Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using specific Visual Studio Project Build configuration for running unit tests

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

like image 396
millie Avatar asked May 19 '26 14:05

millie


1 Answers

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/

like image 148
Mohamed.Radwan -MVP Avatar answered May 22 '26 10:05

Mohamed.Radwan -MVP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!