20 October 2014

Having tests that have long execution time sux, but sometimes you can’t avoid it. Recently I’m involved in development of Windows Phone apps. Few tests have execution time longer than 1 second (ensuring throtling works as it should, integration tests,..).

I’m using MSTest framework and I have created an attribute for this tests:

public class LongRunningTestAttribute : TestCategoryBaseAttribute
{
    public override IList<string> TestCategories
    {
        get { return new List<string> {"LongRunning"}; }
    }
}

This is a sample of long running test:

[TestMethod, LongRunningTest]
public async Task TestThatTakesHisTime()
{
    //....
}

This is a snippet from my psake script:

FormatTaskName "-------- {0} --------"
Task Default -depends Build
properties {
    $vstest = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
}
 
Task LibTests -description "run all library tests" {
  Exec {
    & $vstest App.Portable.Test\bin\Debug\App.Portable.Test.dll /InIsolation /TestCaseFilter:"TestCategory!=LongRunning"   }
}
 
Task LongRunningTests -description "runs longrunning test" {
Exec {
    & $vstest App.Portable.Test\bin\Debug\App.Portable.Test.dll /InIsolation /TestCaseFilter:"TestCategory=LongRunning"   }
}

Invoking LongRunningTests task will run only tests with LongRunningTest attribute and invoking LibTests will execute tests without LongRunning category.



blog comments powered by Disqus