When to execute Pester Tests (Deployment of your DSC Configurations/DSC Resources)

71 views
Skip to first unread message

Michael Landeros

unread,
Mar 20, 2017, 5:09:35 PM3/20/17
to Pester
Hi Group,

I have been testing out PowerShell DSC for a couple of months and came across the Pester Framework. Ideally, I would like to have an Infrastructure deployment pipeline setup where I can execute a build from within my IDE which compiles all of my DSC resources and pushes them out to a share and calls my Deployment Application to push out the new changes and execute my new DSC changes. My question is "When do you think it is best to execute Pester Tests?"

Do you execute them locally before you make it to your Test/Non-prod environment?

Do you execute them once they get to your Test environment and then proceed to QA type environments if all tests pass?

I am open to ideas. Can you provide me with a high-level deployment pipeline for your DSC Configurations/Resources?

Thanks everyone!
-Michael

Chris Dent

unread,
Mar 22, 2017, 8:00:07 AM3/22/17
to Michael Landeros, Pester
It depends on your goals the how exhaustively you want to test.

Personally, for anything really extensive I have:

1. Tests that test the logic of individual functions / classes / methods. I think of this (rightly or wrongly) as unit testing.
2. Tests that validate the outcome of applying code to a blank machine (created via vagrant).
3. Tests that can be used to validate the code has been applied to a real host.

> My question is "When do you think it is best to execute Pester Tests?"

At the very least, unit testing to verify what you're trying to push isn't broken in some way. Syntax testing only goes so far after all. It takes time to write the tests, but that time can be reclaimed by not having to debug typographical or logic errors after you've attempted to push code.

Anything on top of that is a distinct bonus.

> Do you execute them locally before you make it to your Test/Non-prod environment?

Yes, my build scripts automatically fail if the code I'm building doesn't have any unit tests present.

> Do you execute them once they get to your Test environment and then proceed to QA type environments if all tests pass?

Not unit tests. The unit tests exist in my repos, but they don't form part of the "built" artefact. However, I might push operational validation tests with code.

The development to release process for me is something like:

1. Spawn a branch (dev) in VCS to start working on a change
2. Develop changes.
3. Develop tests (arguably this might come first, but I'm not quite up to TDD yet).
4. Execute unit tests
5. Pull to master.
6. Build server triggers on commit to master
7. Build server executes unit tests
8. Build server does everything required to package the module / resource / whatever
9. Build server pushes to the artefact to a feed (in my case, a nuget repo)
10. Clients consume code

I haven't read it, but you might find it useful.


Hopefully it doesn't entirely disagree with my approach :)

HTH

Chris

--
You received this message because you are subscribed to the Google Groups "Pester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pester+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Landeros

unread,
Mar 22, 2017, 11:25:48 AM3/22/17
to Pester
Hi Chris,

First, thank you for your feedback. I have never heard of Vagrant before, so you have already given me something to play with on my free time.

Right after I posted on this Group board I came across an old but still relevant article on Pester Unit / Integration / Acceptance testing - https://blogs.technet.microsoft.com/heyscriptingguy/2015/12/16/unit-testing-powershell-code-with-pester/

It sounds very interesting on how you have things set up. I ultimately would like to have something very similar to yours. Currently I have my PowerShell code/resources/etc. in a repository but I do not have a concept of Master / Branches yet. This is something I am still very "green"  at and never had the pleasure to create, but I am eager to continue my efforts to create a build process. Are you aware of any great articles on branching code? I work 100% with Windows Products (TFS, VS, VSC).

I have came across the book, but have not read it myself either. I may pick it up as I continue my efforts with testing.

Thank you again, Chris, for the details.
-Michael

Chris Dent

unread,
Mar 25, 2017, 6:08:04 AM3/25/17
to Michael Landeros, Pester
There's a pretty good article on at least one style of branching here:

https://www.atlassian.com/git/tutorials/comparing-workflows

It's git, of course, but I suspect many of the general approaches can be applied to other VCS.

--

Michael Landeros

unread,
Mar 28, 2017, 2:05:49 PM3/28/17
to Pester
Awesome! Thanks again. I'm reading this now for my lunch break. 

On Monday, March 20, 2017 at 4:09:35 PM UTC-5, Michael Landeros wrote:
Reply all
Reply to author
Forward
0 new messages