Powershell Unit Testing

on Friday, April 25, 2014

Unit testing is always good practice, but with newer languages there aren’t tools available to provide that functionality. So, it’s always awesome when someone uses their time to make the tool. Jon Wagner did an awesome job and put together:

PSMock/PShould/PSate - a collection of PowerShell modules that setup unit testing. And, he makes them really easy to install with a wiki article describing the steps. I think I was setup and (poorly) writing unit tests in about 15 minutes.

image

For installation, I went the PSGet route. I used PSGet because I like package managers, they take a lot of the pain out of updating. And, PSGet could be installed through a package manager itself (PSGet from Chocolatey).

On a side note, the use of Chocolatey is great because the Windows Server team recently announced that they would use Chocolatey as the primary repository for sharing installs through the OneGet PowerShell module.

I wonder if there’s an easy way to run the unit tests in TFS, and use the results for gated checkins?

 

I also poked around at the work of Adam Driscoll, mostly his PowerShell Tools for Visual Studio. It’s pretty interesting because you get the full Visual Studio debugging experience, which reveals a lot of the environment variables you may not be aware of. I certainly wasn’t.

image

It adds in PowerShell projects as a first class citizen and gives you an alphabetically ordered drop down of all the functions in a module. I like the navigational drop down feature soo much that I would love to see it in the PowerShell ISE.

image

image

It’s a really nice VS plugin and I use it when debugging difficult problems where I want to see the state of a lot of variables at the same time.

However, for most development I continue to use the PowerShell ISE. The ability to run scripts instantly and fluidly switch between the command window and script window is something that I missed when using Visual Studio.

0 comments:

Post a Comment


Creative Commons License
This site uses Alex Gorbatchev's SyntaxHighlighter, and hosted by herdingcode.com's Jon Galloway.