- Write tests before code, expecting them to fail
- Build out code that adds the behavior the test looks for
- Rerun the test
- One very large customer uses an abbreviation of their company name, instead of state code
- Most systems pad with zeros, some do not (e.g. TX001 in some systems is TX1 in others)
- Most systems use a 3 digit number, some use four (e.g. TX001 vs TX0001)
Please build a function that takes a site id (the siteid can be two digit state code and 1, 3, or 4 digits, or 3 digit customer code and 1, 3, or 4 digits). The function should also take a “target domain” which is where the site id will be used (for example “citrix” or “bi”). The function should convert the site id into the right format for the target domain. For example if TX0001 and Citrix is passed in the function should convert to “TX001”. If TX001 and “BI” are passed in the function should convert to “TX0001”.
It’s not terrible, but it gets more complex when you start unpacking it and notice the details I may have forgotten to add. What if the function gets passed an invalid domain? What should the signature look like? What module should the function go into?
And it gets clarified when we add a simple unit tests with lots of details that feel a little awkward to put in the card.
Describe "Get SiteID by domain tests" {
InModuleScope CommonFunctions {
It "converts long id to short for citrix" {
Get-SiteIdByDomain -siteid "TX0001" -domain "citrix" | Should be "TX001"
}
}
I’m not suggesting you stop writing cards or user stories, rather the right answer usually seems to be a little of both. Some verbiage to tell that background, give some motivation for the card, and open a dialog with the engineer doing the work. Some unit tests to give more explicit requirements on the interface to the function.
This approach also leaves the engineer free to pick their own implementation details. They could use a few nested “if” statements, they could use powershell script blocks, or anything else they can think of (that will pass a peer review). As long as it meets the requirements of the unit test the specifics are wide open.
A note about TDD
- You’re using an unfamiliar SDK or framework, TDD will slow down your exploration
- You have a small script that is truly one time use, TDD isn’t worth the overhead
- You have a team that is unfamiliar with TDD, introducing it can be good, using it as a hard and fast rule will demoralize and delay