StatLight

StatLight is an open-source test runner that can execute Silverlight unit tests and report results as an XML file. It supports tests decorated using MSTest attributes, used as default by Silverlight Unit Testing Framework, and can generate results file in the MS Test format.

Some other most important features:
  • It is very easy to deply - all you have to do is to unzip the downloaded file.
  • StatLight is just an executable, so it is easy to integrate with any build system.
  • It supports tests created using other unit testing frameworks, such as NUnit, UnitDriven and XUnit
  • It can automatically close windows created by MessageBox.Show and assertions. As we learnt in the Silverlight team, this is must-have feature for any test runner.
  • It can run tests in Firefox and Chrome.

Links

Project website: http://statlight.codeplex.com/.
License: Microsoft Public License (http://statlight.codeplex.com/license)
Integrating StatLight with TFS test system: http://www.nielshebling.de/?p=167

Samples

Running from command line

StatLight.exe -x bin\debug\SilverMindMap.Core.Tests.xap

Using Chrome or Firefox to run tests

StatLight.exe -x bin\debug\SilverMindMap.Core.Tests.xap -b=Chrome
StatLight.exe -x bin\debug\SilverMindMap.Core.Tests.xap -b=Firefox

Running only tests with tag "Priority0"

StatLight.exe -x bin\debug\SilverMindMap.Core.Tests.xap -t=Priority0

Integration with MsBuild

You can use the Exec task to execute StatLight.exe and run you unit tests. The Silver Mind Map project defines a new Target that uses StatLight to run unit tests:
  <!-- 
    This target runs unit tests created with Silverlight Unit Test Framework 
    Used properties:
      TestXapFile:    path to the XAP file with unit tests
      TestResultFile: path where the XML result file will be saved.
      TagFilters:     (optional) additional tag filter expression for the Silverlight Unit Test Framework.
      
    This target succeeds only when all tests pass.
  -->
<Target Name="RunUnitTests"
          Inputs="$(TestXapFile)"
          Outputs="$(TestResultsDir)\$(TestResultFile)">
    <PropertyGroup>
      <TagFiltersArgument Condition="'$(TagFilters)' != ''">-t=$(TagFilters)</TagFiltersArgument>
      <XapFileArgument>-x=$(TestXapFile)</XapFileArgument>
      <ResultFileArgument>-r=$(TestResultFile)</ResultFileArgument>
      
      <StatLightCommandLine>$(StatLightPath) $(XapFileArgument) $(ResultFileArgument) $(TagFiltersArgument)</StatLightCommandLine>
    </PropertyGroup>
    
    <Exec Command="$(StatLightCommandLine)" ContinueOnError="false"/>
</Target>

This task is invoked after each build of the SilverMindMap.Tests.targets. Notice the TagFilters property - in this case, it is used to run only tests tagged as BVT after each build.

<!-- Properties used by unit tests -->
<PropertyGroup>
    <TestXapFile>$(OutputPath)\$(XapFilename)</TestXapFile>
    <TestResultFile>$(TestResultsDir)\$(AssemblyName).results.xml</TestResultFile>
    <TagFilters Condition="'$(TagFilters)' == ''">BVT</TagFilters>
</PropertyGroup>

<!-- Extending the Build target and running Priority0 unit tests after each build -->
<Import Project="$(SolutionDir)\BuildScripts\SilverMindMap.Tests.targets" />  
<PropertyGroup>
    <BuildDependsOn>
      $(BuildDependsOn);
      RunUnitTests
    </BuildDependsOn>
</PropertyGroup>

Last edited May 18, 2011 at 12:01 PM by _incognito_, version 4

Comments

No comments yet.