Skip to content

Running Tests with Invoke Tests

Jon Wagner edited this page Feb 18, 2013 · 2 revisions

Running Tests with Invoke-Tests

Once you have a bunch of test scripts, you will want to run them as a batch as part of your automated build process. You do this with Invoke-Tests.

Specifying the Tests to Run

Invoke-Tests takes a path and looks for all of the .Tests.ps1 files in the path. You can also tell it to look recursively:

# run all of the tests in the current folder
Invoke-Tests

# run all of the tests in Calculator.Tests.ps1
Invoke-Tests c:\projects.net\psst\tests\Calculator.Tests.ps1

# run all of the tests in the psst folder
Invoke-Tests c:\projects.net\psst

# run all of the tests in the psst folder and below
Invoke-Tests c:\projects.net\psst -Recurse

If you want to have more control over the tests that are run, use the -Filter option. See Filtering Tests with Invoke-Tests for more info.

Controlling the Output

By default, Invoke-Tests outputs The Test Log but you can tell it to output other things:

# shh. nothing.
Invoke-Tests -Output Quiet

# output the log (default)
Invoke-Tests -Output Log

# output the results as an object structure
$results = Invoke-Tests -Output Results

# output the results as an NUnit XML file
Invoke-Tests -Output NUnit > testresults.xml

# output the results object to a variable $results, and the log to the output stream
Invoke-Tests -Output Log -ResultsVariable results

Outputting an NUnit File

You can also tell Invoke-Tests to output an NUnit file in addition to the output stream. This will be a common case for automated build processes.

# outputs the log to the stream, and the NUnit results to testresults.xml
Invoke-Tests -Output Log -NUnit testResults.xml

Generating an Exit Code

The -ExitCode switch tells Invoke-Tests to exit the process with the number of failed tests. This will be a common case for automated build processes.

NOTE: if you run this interactively, you will close your PowerShell window.