Wednesday, February 6, 2008

Creating .testrunConfig files to run .Net Compact Framework Unit Tests on different platforms and devices

Currently we have the possibility to run .Net CF unit tests on the device (or emulator) and additionally, we can include unit test runs on our automated build processes. In the first case, it's very important to know how to define where the unit tests will run; and that is possible using test run configuration files (.testrunConfig).

By default, when you create a Smart Device Unit Test project, Visual studio includes a "[SolutionName].testrunConfig" file into the Solution Items folder, as follows:

image

It includes the default configuration according to your project platform. If you double click the .testrunConfig file, it will be open with the Test Run Configuration Editor, a very friendly tool which help us to edit a .testrunConfig file using a nice UI which looks like this:

image

We can also modify the file with the XML Editor if you right click on the file and select "Open with...". But let's see what we can do using this Test Run Configuration Editor.

Unfortunately, Code Coverage is not supported for Smart device projects, but you can play around with the other options, and particularly in this post, I want to focus on the Hosts group.

image

Here we can define on what platform we want to our unit tests run:

image 

Or even better, we can define the device where the unit tests will run:

image

Very cool stuff! Does It mean that we can change the settings targeting a different platform whenever we need to run the tests on it? Yes, but we can have more than one .testrunConfig files, which means we can have different configurations on each file.

We can change the settings as follows and press the Save As... button

image

And save the file as SmartphoneWM5.testrunConfig

image Now we have two .testrunConfig files in the solution, and we can add a third one right clicking the solution and selecting Add - New Item... and selecting Test Run Configuration in Categories:

image

And entering and applying the settings on the Test Run Configuration Editor. Now we have three .testrunConfig files on the solution. How we select the current Test Run Configuration file?. Just go to Test menu and select it!

image

Or if you're using MSTest.exe to run the tests from the command line or an automated build, you can select the .testrunConfig file using the /runconfig parameter as I did in this post.

<Exec Command="MSTest /testcontainer:bin\debug\testproject1.dll /runconfig:..\SmartDeviceTestRun.testrunconfig" />


Nice! Now you can create several configuration files and run your tests on different platforms and devices. Enjoy!

No comments: