KCDC — SEPT 17, 2021
BUILT-IN TESTING IN GO IS MORE THAN JUST PASSABLE Scott McAllister PagerDuty @stmcallister
Slide 2
Slide 3
Slide 4
go-pagerduty library
@stmcallister
Slide 5
Slide 6
Slide 7
Slide 8
The Go programming language is an open source project to make programmers more productive.
Slide 9
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
Slide 10
Testing Evaluate and verify that the code does what is expected
@stmcallister
Slide 11
Unit Testing Testing the smallest piece of code that can be logically isolated
@stmcallister
Slide 12
Integration Testing Testing combined modules as a group
@stmcallister
Slide 13
Testing in Go @stmcallister
Slide 14
TESTING IN GO Test code typically lives in the same package as the code it tests
@stmcallister
Slide 15
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
Slide 16
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