GeistHaus
log in · sign up

testing

golang.org

Package testing provides support for automated testing of Go packages.

47 pages link to this URL
Table-Driven Test Design

Personal Website of Patrick Bucher (paedubucher), mostly about IT-related topics (programming)

0 inbound links en ProgrammingITComputer ScienceUnixLinux
Learning Go-Fuzz 2: goexif2

Previously on Learning Go-Fuzz: "Learning Go-Fuzz 1: iprange" This time I am looking at a different package. This is a package called goexif at https://github.com/rwcarlsen/goexif. Being a file parser, it's a prime target for Go-Fuzz. Unfortunately it has not been updated for a while. Instead, we will be looking at a fork at https://github.com/xor-gate/goexif2. Code and fuzzing artifacts are at: https://github.com/parsiya/Go-Security/tree/master/go-fuzz/goexif2

0 inbound links en [Parsia Hakimian Parsiya infosec information security]
Golang basics - writing unit tests

Learn to write unit tests in Golang as we explore the basics then move onto isolating dependencies, fakes and code coverage with the Go's standard tools.

2 inbound links article en golangcodingbasicsunit testinggolang basicsjson
Running benchmarks for Pull Requests via GitHub Actions

Benchmarks are often underestimated and don’t get the same attention as tests. However “performance is a feature” and when something is not tested it might as well be just broken. If the performance is not measured/tracked regressions are inevitable. Modern tooling makes it really easy to write benchmarks. Some languages have built-in support, for example, Rust comes with cargo bench (docs) and Go has go test -bench (docs). For C++ there is google/benchmark – not as streamlined as having it built into the language infrastructure, but still definitely worth the effort.

0 inbound links article en posts blogdeveloperpersonalbenchmarkcigithub-actions
godoc

Godoc extracts and generates documentation for Go programs.

godoc

Godoc extracts and generates documentation for Go programs.

Testing with Go

An integral part of the development licefycle is writing tests. Write tests early, write tests often as they say. Go makes it very easy to write tests. The following post will go through the basics of testing with Go. Let’s say we have a program that counts the number of vowels, consonants, digits and everything else within an input string. It may look something like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 package main import ( "flag" "fmt" ) // CountChars counts the number of characters in a string func CountChars(str string) (int, int, int, int) { vcount := 0 ccount := 0 dcount := 0 ocount := 0 for i := 0; i < len(str); i++ { switch str[i] { case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U': vcount++ case 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z': ccount++ case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0': dcount++ default: ocount++ } } return vcount, ccount, dcount, ocount } func main() { inputStr := flag.String("inputStr", "", "The input string") flag.Parse() vowels, consonants, digits, other := CountChars(*inputStr) fmt.Println("Number of vowel chars: ", vowels) fmt.Println("Number of consonant chars: ", consonants) fmt.Println("Number of digit chars: ", digits) fmt.Println("Number of other chars: ", other) } Go provides a testing package to help with writing unit tests. Unit tests are contained in files typically ending in *_test.go. So to test the main function, you would have main_test.go in the same directory and so on. Files whose names begin with _ or . are ignored. There are three types of functions that are typically contained in a test file: TestXxx, ExampleXxx, BenchmarkXxx

0 inbound links article en posts Tech
Travis/AppVeyor CI Script for Go

Continous Integration tests are an important part of maintaining package stability. Since Travis has recently made it possible to run tests on OSX and with AppVeyor having Windows support, we now can create free CI tests for all the major desktop platforms. For my various packages, I find that I commonly copy+paste my CI tests,…

0 inbound links en GoProgrammingtesting
When is Go a nice language?

I’ve been following Go for a while due to the influence of one of my personal heroes: Ken Thompson (due to his hand in making Unix and C programming language).

0 inbound links article en
Go: the Good, the Bad and the Ugly

This is an additional post in the “Go is not good” series. Go does have some nice features, hence the “The Good” part in this post, but overall I find it cumbersome and painful to use when we go beyond API or network servers (which is what it was designed ...

4 inbound links article en
Testing in Go: Failing Tests

A short overview of the testing package # The testing package from Golang’s standard library provides support for automated testing of Go packages.

0 inbound links article en Posts