Testing in PowerShell

I made a thing! A thing in PowerShell!

I’m not really sure how to make a module in PowerShell, but I made functions to do these epoch conversions and put them in a .psm1 file. Don’t know if there’s more to it or not.

Naturally, I wanted to write tests as I worked. I discovered that there is no testing framework in PowerShell, but there’s a terrific third-party framework called Pester. Since PowerShell on Linux is so new, I had no idea if it was going to work. I was pleased when it installed without issue, but at first it didn’t appear to work. Turns out it was assuming I had a $env:TEMP defined, but I had not. I took a guess and just set it to /tmp

$env:TEMP = '/tmp'

and then all was well! When you are in the directory where your module and tests are, you can import your module with

Import-Module ./Epochs

and then run your tests with


That is, if we’ve named everything the way Pester expects, we just take all the defaults!

I learned the hard way that PowerShell won’t re-import a module it has already imported, by default. Making changes to Epochs.psm1 and then doing

Import-Module ./Epochs

made me think my tests were still passing with my code changes, but it hadn’t actually reloaded my module. You have to -force it

Import-Module ./Epochs -force

I’m still stumbling around when it comes to PowerShell, but Pester makes me feel more at home!

Testing in PowerShell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s