Hi,
I have two test files and I am calling a function from within another test file. However, I get undefined
errors while running the tests. Am I missing something here?
Thanks
This on its own works fine
setUp
hello
test
tearDown
bye
# internal/lib/client_test.go
package client
import (
"fmt"
"testing"
)
var a string
func setUp() {
a = "hello"
fmt.Println("setUp")
}
func tearDown() {
a = "bye"
fmt.Println("tearDown")
}
func TestController_Create(t *testing.T) {
setUp()
fmt.Println(a)
fmt.Println("test")
tearDown()
fmt.Println(a)
}
This doesn’t work
undefined: setUp
undefined: a
undefined: tearDown
undefined: a
# internal/lib/client_test.go
package client
import (
"fmt"
"testing"
)
func TestController_Create(t *testing.T) {
setUp()
fmt.Println(a)
fmt.Println("test")
tearDown()
fmt.Println(a)
}
# internal/lib/common_test.go
package client
import (
"fmt"
)
var a string
func setUp() {
a = "hello"
fmt.Println("setUp")
}
func tearDown() {
a = "bye"
fmt.Println("tearDown")
}