Go의 Test에 대한 기본적인 내용은 Doc 참고.
유닛테스트를 하려면 함수를 export 해야 하는데, 테스트를 한답시고 모든 함수의 첫글자를 대문자로 작성할 수는 없다.
이를 해결하기 위해 export_test.go 파일을 생성한다. 포인트는 package를 example_test가 아니라 example로 설정하는 것.
[파일명]_test.go 에서는 export_test.go에서 export한 함수를 사용할 수 있다.
export_test.go
package example
// Export for test
var ExampleFunc = exampleFunc
example_test.go
package example_test
import (
"testing"
"[package 경로]/example"
)
func TestExampleFunc(t *testing.T) {
...test 코드...
}