Package testing

Table of Contents

Basics of testing tutorial

import "testing"

func TextXxx(t *testing.T) {
    t.Errorf("Failed! %d", 10)
}
func BenchmarkXxx(b *testing.B)
func ExampleXxx()
setup and teardown

How test files are treated within a package dicussion

You exploit this characteristic to expose internal functions for testing. For example:

export_test.go
package foo

// `doSomething` is defined in some other normal file and it is intended to use internally.
// However, if you want to use this internal function in an external package for testing,
// You can expose it only for testing as follows.
// Since the line is declared in `_test.go` file, it is exposed only during testing.
var DoSomething = doSomething