Comments (2)
If you test the individually and then build the module you aren't accurately testing the code that you're shipping, simple things like $script: or $global: variables may be set in functions that break interactions in other functions but pass the tests.
This is solved with an Imports file: https://github.com/techthoughts2/Catesta/blob/master/src/Catesta/Resources/Module/src/Module/Module.psm1#L4
It permits availability of all script or globally scoped variables.
Have the test and analyze steps depend on the build step.
There is a drawback to this approach. The test function needs to import the module. In current form, that imports the de-constructed psm1. The benefit to this is that you get the ability to run individual pester tests against one function. If your change were implemented, the pester function test would need to be updated to reference the build location. That means you would have to run a build locally every time you wanted to test a function during development.
For unit testing I feel like that is not a trade-off worth taking. I'm open to discussing if you have an idea of supporting both scenarios.
I do agree that you make a valid point for infra tests. I will pop a new issue to have infra tests moved to post build.
from catesta.
Have the test and analyze steps depend on the build step.
There is a drawback to this approach. The test function needs to import the module. In current form, that imports the de-constructed psm1. The benefit to this is that you get the ability to run individual pester tests against one function. If your change were implemented, the pester function test would need to be updated to reference the build location. That means you would have to run a build locally every time you wanted to test a function during development.
For unit testing I feel like that is not a trade-off worth taking. I'm open to discussing if you have an idea of supporting both scenarios.
I do agree that you make a valid point for infra tests. I will pop a new issue to have infra tests moved to post build.
Ensuring the Tests import the module is pretty easy, just add the build output location to the beginning of your PSModulePath as part of the build process and you'll always import that version first. That way you don't care about where the module is output and you can test the whole thing easily.
As a way to test individual functions, my approach for that has been to tag the Describe blocks for each test script with the name of the function it's testing, that way I can run my build script with a -Tag
parameter and just run the functions I want to. Building the module takes 5 - 10 seconds usually so I'm willing to accept that small amount of time being added to my local build process, especially when I'm usually just hitting F5 in VSCode to trigger it. And running a build locally is how other programming languages have to do it and some of those take a lot longer to build, it's not a huge trade off to ensuring that you've got the latest version of the code in your module files, especially if you then go on to do some manual exploratory testing.
If you test the individually and then build the module you aren't accurately testing the code that you're shipping, simple things like $script: or $global: variables may be set in functions that break interactions in other functions but pass the tests.
This is solved with an Imports file: https://github.com/techthoughts2/Catesta/blob/master/src/Catesta/Resources/Module/src/Module/Module.psm1#L4
It permits availability of all script or globally scoped variables.
That was just one example of possible issues with this approach. There's also the length of time it takes to import dot sourced modules, it's not a huge amount of time but can get to 1 - 2 seconds easily per import. Not an issue for an end user usually but if you're running 10+ test scripts it adds up and anything that can be done to speed up the build and test process is well worth it.
from catesta.
Related Issues (20)
- Write docs outside of artifacts directory HOT 3
- Leverage Update-Markdownhelp when generating docs
- Improve ExportedFunctions check
- Remove Export-ModuleMember from Catesta.psm1 HOT 1
- Scaffold new project - .gitignore file missing? HOT 3
- ModuleOnly states that it scaffolding a GitHub Actions module
- On certain Linux distro an error is occuring stating file not found
- Upgrade Pester and some of the dependencies HOT 2
- Missing comma in tasks json
- Add Pester 5 capabilities
- Evaluate latest version of platyPS for help creation HOT 3
- Old Pester syntax is used for should in module tests
- Assert-MockCalled being deprecated in Pester 5
- Casing issue related to folder Editor which causes undesired behavior on certain OS's HOT 1
- Add template example for GitHub SECURITY.md file
- GitLab support for CICDChoice HOT 1
- Vanilla module and Vanilla vault do not include support for PlatyPS external help generation HOT 1
- VSCode question prompt not present in all templates
- Bitbucket support
- Build task fails if docs folder does not exist already HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from catesta.