Overview
For this point forward, we assume you have a working environment. To verify this, here is a a quick smoke test of your environment to make sure things work well enough to proceed. After this, we’ll look at implementing an algorithm to practice the TDD cycle. Finally, we’ll dig into a larger problem to look into OOP and Design Patterns.
Primordial Beginnings
A good start is to verify that you can run tests, they fail, and you can make them pass. So to get started, open up an instance of PowerShell and try the following:
- Create a directory to store your work, I’ll use C:\Users\Brett:
- And the result
- Switch to that directory to do all of the remaining work in this example:
- Next, check that Pester is properly installed and you can run it in the shell:
- The expected result:
This tells me that we can run Pester from the shell. We will look at a few more ways to run tests, but this is enough to get started.
First Failing Test
A good practice is to make sure tests fail before they pass. This makes it easy to verify that your tests are running.
- Use your favorite editor (vim for me), and create the following file called Trivial.Tests.ps1:
- This should fail because the size of the array is 0. To be sure, try running it in the shell:
- To make this test pass, we either change the value or the array. I’ll update the array:
- And again, run the tests to see if things are any better:
Congratulations, you’ve got a working system. Rather than spend more time on this trivial example, we’ll move on to a more complex problem. Previous
Comments