Forum Discussion
cunderw
8 years agoCommunity Hero
Not sure if this will help exactly with how you want to run your tests, but the way we do it is all of our projects are stand-alone (ie. not tied to a single project suite as we have several hundred of them) and we store a list of project paths in a text file.
We then use the following powershell script to automatically grab and run the next test on the list. This even works for distributing the load if you have the test list stored on a network share. Each running computer will just wait until the file is unlocked and grab whatever test is next on the list.
Here's the code for the powershell script we use:
function Get-LockedFile($FN, $FileMode,$FileAccess) { #Opens a file in locked mode and returns a file handle. If the file is locked it waits until it becomes available. $FileHandle = $null while ($FileHandle -eq $Null) { try { $FileHandle = [System.io.File]::Open($FN, $FileMode, $FileAccess, 'None') } Catch { Start-Sleep -Milliseconds 500 } } $FileHandle } function GetNextTest($app) { $FileName = "<PathToTestList>" $File = Get-LockedFile $FileName "Open" "ReadWrite" $Reader = New-Object System.IO.StreamReader($File) $NextTest = $Reader.ReadLine() if ($NextTest -eq "") {$NextTest = "EOT"} $RestOfFile = $Reader.ReadToEnd() $File.SetLength(0) $Writer = New-Object System.IO.StreamWriter($File) $Writer.WriteLIne($RestOfFile) $Writer.Flush() $File.Close() $NextTest } function LogTestCase($TC) { $Date = Get-Date -Format "yyyyMMdd" $File = Get-LockedFile "<pathToRunLog>" 'Append' "Write" $Writer = New-Object System.IO.StreamWriter($File) $TS = Get-Date $LogText = "$TS`t$env:computername`t$TC" $Writer.WriteLIne($LogText) $Writer.Flush() $File.Close() } function closeTestExecute() { $testExecute = Get-Process TestExecute -ErrorAction SilentlyContinue if ($testExecute) { # try gracefully first $testExecute.CloseMainWindow() # kill after five seconds Sleep 5 if (!$testExecute.HasExited) { $testExecute | Stop-Process -Force } } Remove-Variable testExecute } function run() { while ($NextTest -ne "EOT") { closeTestExecute $NextTest = GetNextTest($app) LogTestCase $NextTest $arg1 = "/r" $arg2 = "/SilentMode" $arg3 = "/e" $arg4 = "/DoNotShowLog" $AllArgs = @($NextTest, $arg1, $arg2, $arg3, $arg4) & "C:\Program Files (x86)\SmartBear\TestExecute 12\Bin\TestExecute.exe" $AllArgs | Out-Null } } run