-
-
Notifications
You must be signed in to change notification settings - Fork 60
Using for Test Automation
Invoke-Build happens to be useful for test automation, especially in PowerShell oriented projects. It is easy and natural to organize PowerShell tests as tasks in build scripts. The following supportive features are offered right away:
-
assert
andequals
are must have features. - Tests start, end, output, and duration logging.
- Tests are invoked individually or by sets (
*, **
). - Tests may have dependencies and hierarchical structure.
- Tests have easy access to files using relative file paths.
- Tests are invoked once even if referenced by multiple parents.
- Build results can be obtained for detailed analysis and reports.
At the same time Invoke-Build is not specifically designed to be a test system. But for lightweight testing of relatively small projects it does the job very well with minimum extra effort. Small or not, Invoke-Build has more than 300 test tasks.
The special tasks *
and **
are used in order to make invocation of tests
easy. The following command invokes all tasks (tests) defined in the script:
Invoke-Build * Smoke.test.ps1
The task **
invokes *
for all files *.test.ps1
found in the directory
Tests and its subdirectories:
Invoke-Build ** Tests
When the switch Safe
is used together with **
then build failures stop
current test scripts, not the whole testing, invocation of remaining test
scripts continues:
Invoke-Build ** -Safe
Safe
is often used together with Summary
or Result
. The switch Summary
tells to print task records including errors after the build. The parameter
Result
is used in order to get build data for further detailed analysis
and reports, see Build Analysis.
With *
and **
there is no need to call tests individually or register them
for testing. As soon as a test task is added to a script, it gets invoked when
a script is invoked with *
. Note that dependencies are taken into account,
*
invokes task trees starting from roots. Without dependencies tasks are
invoked in their natural order in scripts.
Unlike **
, the batch task *
is found useful not just for tests. Some
scripts may be designed so that their tasks should be invoked together.
Below is the list of some projects where all tests are implemented as tasks and tested by Invoke-Build exclusively. The links are project directories with tests.
- Concepts
- Script Tutorial
- Incremental Tasks
- Partial Incremental Tasks
- How Build Works
- Special Variables
- Build Failures
- Build Analysis
- Parallel Builds
- Persistent Builds
- Portable Build Scripts
- Using for Test Automation
- Debugging Tips
- VSCode Tips
Helpers
- Invoke Task from VSCode
- Generate VSCode Tasks
- Invoke Task from ISE
- Resolve MSBuild
- Show Build Trees
- Show Build Graph
- Argument Completers
- Invoke-Build.template
Appendix