PowerShell TDD with PSUnit

My own Cliffs Notes on PowerShell unit testing. Hope it helps you as well. I may update this as I move along.

1. For serious, robust programming, TDD is definitely the way to go;

2. I looked at both Pester and PSUnit. Despite the 10 votes (so far) for the Pester answer on a stackoverflow question, my tinkering with both led me to conclude that I will use PSUnit.

Overall, the notes here are helpful, but I needed to tweak a few places to get it working in my dev environment.

3. The download zip file from CodePlex has the timestamp of 20090806 and has Beta status. Don’t worry about it;

4. Move files around and create directories as necessary. You need to check each ps1 file’s property and click Unblock. It will be nice to have this automated;

5. After creating a PowerShell profile under C:\Users\haidong\Documents\WindowsPowerShell and copying the profile files, profile.ps1 needs to be modified: $PSUnitPath = “C:\Users\haidong\PSUnit”;

6. Microsoft.PowerShellISE_profile.ps1 also needs to be modified. Comment out the CTP3 line and uncomment the . PSUnit.ISE.ps1 line;

7. Run PowerShell as Administrator. You need to do this even if you are logged in as Administrator. Then do “set-executionpolicy RemoteSigned”;

8. The ISE addon menu is really handy. If you are running Windows 2008 R2, PowerShell ISE may not come installed. Add this feature using Server Manager.

2 thoughts on “PowerShell TDD with PSUnit”

  1. Hi Josep,

    Strange that you couldn’t comment. Sorry about that. I will post this exchange on my blog.

    There are mainly two reasons I didn’t choose Pester: 1. I know that BDD is based on TDD, but I’ve never used it myself; 2. My memory is vague now but I seem to remember that I had trouble installing Pester and its required component. It’s interesting that Pester’s github page is down at the moment.

    As to PowerSpec, I didn’t come across it during my research therefore it wasn’t even an option for me then. But looking at the doc on github, I don’t think I would choose it either, mostly because I am not used to write tests that way.

    So far PSUnit works fine for me. I’ve used it to develop some scripts for Windows file string manipulation. I like the fact that there are two ways of running unit test suites: from PowerShell ISE on PowerShell command line. I’ve used command line most of the time.

    I’ve got to say that PSUnit and Pester’s documentation leaves a lot to be desired. I may write a blog or two about how I used PSUnit.

    I am frankly surprised that PowerShell didn’t come with a xUnit test framework baked in. It is a relatively new language, after all. I dare say that in designing a new language, having a native unit test framework from the beginning is a requirement.

    Haidong

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.