lidingshan/PSUnit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
*********************************************************** What is PSUnit *********************************************************** This is a simple unit test frameworkk for powershell script. Right now, it support the following assert and setup/teardown 1. assertAreEqual 2. assertGreater 3. assertLess 4. assertFail 5. assertIsNone 6. assertIsNotNull 7. setup 8. teardown 9. fxiture_setup 10. fixture_teardown *********************************************************** How to run the test script? *********************************************************** Before running the test, please set up a environment variable first called "PSUNIT_HOME" what value is the folder of PSUnit. Then you may run the test script like bellow 1) Start a command terminal 2) Go to PSUnit home folder 3) Execute the BAT file under the home folder called run_test.bat with one input argument what is the folder name include the test scripts you want to execute 4) Or you may run PowerScript directly, like PowerShell .\testRunner.ps1 [the folder name include test scripts] PSUnit will find each PowerScript file (.ps1) under the folder provided recurvsely which file name match the pattern of "test*.ps1". And then it will execute all of the functions that match the patter of "function test*" in each script file. For test fixture setup and teardown, you may implement the methods of * fixture_setup * fixture_teardown The fixture_setup will be invoked before any test cases being executed and fixture_teardown will be invoked after all of the test cases being invoked. So they can be used for a test fixture initialization and cleanup. The setup method will be invoked before each test case being executed and teardown method will be invoked after one test case being executed. So they can be used for one test case initialization and cleanup. *********************************************************** Example *********************************************************** If your test scripte files are under the folder of C:\test, then you can run your tests like run_test.bat C:\test Or PowerShell .\testRunner.ps1 c:\test 2. Tests examples File name: test_calculation.ps1 and in the script file to add functions to execute the tests, like Import-Module $env:PSUNIT_HOME"\asserts.psm1" function test_add() { $expected = 5 $actual = 3 + 2 assertAreEqual $expected $actual } *********************************************************** Knowing Issues *********************************************************** Right now, PSUnit cannot handle the comments in test scripts. So even if one function has been commented, like "# function test_add()", PSUnit will still run this test.
About
A unit test framework for PowerShell
Resources
Stars
Watchers
Forks
Packages 0
No packages published