KCDC — SEPT 17, 2021 BUILT-IN TESTING IN GO IS MORE THAN JUST PASSABLE Scott McAllister PagerDuty @stmcallister

go-pagerduty library @stmcallister

The Go programming language is an open source project to make programmers more productive.

Really, Really Brief Introduction to Go ● Released by Google in 2009 ● Designed to help solve Google’s problems ● Main Characteristics ○ Open-Source ○ Statically Typed ○ Concurrency Support ○ Powerful Standard Library ○ Built-in Testing ○ Garbage Collection

Testing Evaluate and verify that the code does what is expected @stmcallister

Unit Testing Testing the smallest piece of code that can be logically isolated @stmcallister

Integration Testing Testing combined modules as a group @stmcallister

Testing in Go @stmcallister

TESTING IN GO Test code typically lives in the same package as the code it tests @stmcallister

TESTING IN GO Test code typically lives in the same package as the code it tests Name of test files end in *_test.go @stmcallister

TEST FUNCTIONS You can define methods on any type: func TestHelloEmpty(t *testing.T) { msg, err := Hello(“”) if msg != “” || err == nil { t.Fatalf(Hello("") = %q, %v, want "", error, msg, err) } } @stmcallister Function names begin with ‘Test’ Functions receive pointer to testing.T

Running Go Tests go test @stmcallister

Subtests @stmcallister

Additional Resources go-test-demos https://github.com/stmcallister/go-test-demos go-pagerduty https://github.com/PagerDuty/go-pagerduty @stmcallister