With MS ramming powershell into all new server products, I'm starting to (reluctantly) think I need to take it seriously. Part of "taking it seriously" is TDD. Have you found good methods to unit test power shell scripts?
I've found samples of mocking from Mr Geek Noise - but I'd really like something like RhinoMocks. Brian Hartsock has a sample of running tests on powershell strings from MS Test. A little hacky, but it seems to work.
What I want is a Powershell TDD experience that is as clean as it is in "real" languages.
Update to clarify:
The first two answers attempt to steer me away from testing Powershell. The opinions are interesting. I don't want to know if it's a good idea to test in powershell. That's a subjective question that should be asked in a different forum. I want a solution to unit testing powershell. If you think it's a bad idea (it might be), treat it as a fun academic question.
To re-state: How do you implement an automated testing of Powershell logic in the style of xUnit? Integration tests are interesting, unit tests that break dependencies most interesting.
Unit testing is the art of creating automated tests for your code, usually after you have written the code. Test-driven development (TDD) is a set of practices where you write your unit tests before writing your production code and continuously run those tests as you write new code.
Unit testing is a type of automated testing. You can write unit testing without using TDD or BDD, just by writing the tests after the production code. TDD is a software development methodology, in which the developer writes code in very short cycles, always starting with a failing test.
These are the rules of TDD. This means that you are only ever writing one unit test and one bit of code at a time and doing this iteratively. The point of TDD is not writing tests, it is using your tests to drive out the design.
Scott Muc has started a project for a lightweight BDD framework for PowerShell called Pester:
https://github.com/pester/Pester
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With