Automated Module Testing – Part 1

Hi all,

As your probably know if you’re reading this blog, I’ve made a Powershell module dedicated to MS Excel. Very Often I do some refactoring and code updates but it is very difficult to be sure before a new release that every little changes I’ve made didn’t introduced some bug… This is a real problem and because I do this during my free time, it is not possible for me to test everything… Many times, by modifying my code I introduced new bugs so I decided to create something to aggregate my code before each release. The code isn’t finished for the moment but… I’ll release it very soon !

For the moment, my code does the following :

  • Retrieve all the Cmdlet of a module
  • Retrieve all the parameters of each Cmdlet
  • Build all the possible combination between all parameters (Taking care of the parameter set, of what is mandatory, what is optional and what could come from the pipeline)
  • Create Script blocks with every parameters you must provide to test all the possibilities but maybe an example will be better to show you what I mean… Just have a look at what comes after this list 😉

Imagine, You have this Cmdlet that is part of a module :

My Script tester would generate the following code (The function name is not valid, I must suppress all “-” from the original Cmdlet… It’s just a theoretical example) :

As you can see for the moment the output is not tested, you can just rely on no error or exception to validate the combination. Of course, my next goal will be to add the possibility to enter the expected result 😉 But I’m on my way… Stay tuned and Bye Bye !