Go R1 Day 5
Day 5 of 100
- I created my first unit test for go
- It’s a bit interesting coming from a background with PowerShell and Pester as my primary unit test framework. For instance, in Pester you’d declare the anything, but autodiscovery works with
*.tests.ps1, being the normal convention.
- There is no pointer value providing the test package, it’s just other PowerShell calling PowerShell.
- I’m biased I know, but the first test condition being like below seems clunky. I was hoping for something that was more like Pester with
test.Equals(got, want,"Error message")as the syntax is more inline to what I’d expect. I haven’t dived in further so this is just a thought, hoping this is just the newbie 101 test case example and there are more succinct comparison and test methods available.
- Update: Good article explaining the opinionated approach with testing and reasoning not to use assertions located at: Golang basics - Writing Units Tests. This is helpful to someone wanting to learn. I don’t want to force my prior paradigms on the language, because basically the whole reason I decided on Go over python or other language was wanting to learn something that helped me think in a fundamentally different way than using dotnet/Powershell. Python is very similar to PowerShell syntax wise for example, while Go is forcing me to look at things from a completely different view.
- I’ll stick with the default package while I’m learning. However, there is a package called Testify that is worth exploring if I find I still want assertions later on.
(No webmentions yet.)