Matt Hinze
Matt Hinze

Reputation: 13679

How do I instruct MSTest to remove all testing artifacts after a test run?

I am running MSTest against our test assembly from the command line:

mstest /testcontainer:C:\dev\UnitTests\bin\Debug\UnitTests.dll

This works fine, except I do not want the artifacts from this run to remain. Seems that MSTest leaves a copy around. For me, they're in the C:\dev\TestResults\ directory.

I have investigated a few things:

How can I remove test run artifacts after the run is completed?

Edit: also, I would accept an answer that will run our MSTest tests using an open source test running tool. I just want to script this, man.

Upvotes: 4

Views: 2242

Answers (1)

Matt Hinze
Matt Hinze

Reputation: 13679

MSTest creates the TestResults directory in $pwd.

function global:runtests()
{
    $mstest = Join-Path $env:VS100COMNTOOLS "..\IDE\mstest.exe" -Resolve

    $resultsDir = Join-Path $pwd "TestResults"

    $testDll = Join-Path $solutionScriptsContainer "..\UnitTests\bin\Debug\UnitTests.dll" -Resolve          
    $output = & $mstest /testcontainer:$testDll 
    $o = [regex]::match($output, "^.*(Summary.*)Results file.*$")
    $mstflag = "MSTest:"
    $op =  $mstflag +=  $o.groups[1].value

    Write-Host $op
    Write-Host "Deleting $resultsDir"

    remove-item $resultsDir -force -recurse
}

Upvotes: 1

Related Questions