Reputation: 1
I currently have a PowerShell module that extends another module. Basically, my new module re-implements one Function to provide custom behavior for a specific customer:
Base Module - Implements 12 Functions and Exports 12 Functions. Customer Module - Re-Implements 1 Function from the Base Module and Exports 12 Functions. Includes Nested Modules = Base Module.
I want to be able to run all of the Base Module tests against the Customer Module. This will ensure there aren't any issues with the configuration of the CustomerModule.psd1
Currently, all the tests are in a file BaseModule.Tests.ps1 with a BeforeAll Block that imports the Base Module.
I have a separate CustomerModule.Tests.ps1 file that has a BeforeAll Block that imports the Customer Module and tests the specific implementation of Function1.
How do I tell CustomerModule.Tests.ps1 I want to execute all of the tests in BaseModule.Tests.ps1 but use the Customer Module Imports instead of the Base Module Imports?
I have tried searching all of the Pester documentation and search engines and have not found any examples or articles describing this use case.
Thanks!
-jeremy
Upvotes: 0
Views: 80
Reputation: 54911
It depends on how you use the module, if the functions are named the same etc. Without seeing any code I can only suggest to generalize the BaseModule.Tests.ps1
and provide things like modulename using parameter, see https://pester.dev/docs/usage/data-driven-tests#providing-external-data-to-tests
That way you could reference the parameter value when you run Import-Module $myParam
, Mock Some-Command -ModuleName $myParam
etc.
Upvotes: 0