Home >Backend Development >Golang >How Should I Name My Go Test Packages for White-Box vs. Black-Box Testing?
When writing tests in Go, developers often face the question of how to name their test packages. The three main strategies are:
Strategy 1: Same Package Name
package myfunc // myfunc.go
package myfunc // myfunc_test.go
Strategy 2: Separate Package Name (with *_test suffix)
package myfunc // myfunc.go
package myfunc_test // myfunc_test.go
Strategy 3: Separate Package Name (with import alias)
package myfunc // myfunc.go
package myfunc_test import . "myfunc" // myfunc_test.go
The key difference between these strategies is whether the test code has access to the non-exported identifiers of the package under test.
Which strategy to use depends on the testing requirements. For white-box testing, Strategy 1 is appropriate, while for black-box testing, Strategies 2 and 3 are preferred. It's also possible to use a combination of strategies in a single project, tailoring the test packages to specific testing needs.
The above is the detailed content of How Should I Name My Go Test Packages for White-Box vs. Black-Box Testing?. For more information, please follow other related articles on the PHP Chinese website!