On Writing Unit Tests

I would consider that I am a beginner at unit testing but these days, I started writing it much more frequently and I am quite proud of it. I noticed that it actually helps me to notice regression early on and as well as helps me to understand how the components work together. I also learned ‘the hard way’ how hard it is to start writing unit tests for an existing project that have 0 unit test.

Go Examples and Benchmarks

I learned about Go examples and benchmarks today. They are parts of Go default package testing. Examples Go Examples are executed just like tests They are compiled and optionally executed as part of unit tests It resides in the package *_test.go files Structure func ExampleRepeat() { repeated := Repeated("x", 5) fmt.Println(repeated) // output: xxxxx } Rules Function name must be prefix with Example It must have // output: result How to Use to run the test with example, use: go test -v Sample Execution $ go test -v === RUN TestRepeat --- PASS: TestRepeat (0.

On Jotting Down

I started reading Joel’s Joel on Software today and there’s this excerpt that I quite like .. if you know something, you need to publish it on the Web for others to learn from. Guessed that’s probably why I did this again. ¯\_(ツ)_/¯

Setting Up $GOPATH

GOPATH specifies the location of your go workspace. By default this will be $HOME/go. You should set your $GOPATH in .zshrc or .bash_profile to be used later in scripts or shell. Add the followings into your .bash_profile: export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin Reload your shell and done. To confirm that it’s working, enter $GOPATH in your shell and it should take you to the go workspace directory.