Skip to content

Go R1 Day 5

Day 5 of 100🔗

progress🔗

  • 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.
package main

import "testing"

func TestHello(t *testing.T) {
    got := Hello()
    want := "Hello, world"
    if got != want {
        t.Errorf("got %q want %q", got, want)
    }
}
  • Update: 2020-08-24 2020-08-24
  • 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.