The problem is that main_test
is a different package from main
.
To access functions in main
you need to import main
and access the functions like this: main.F()
Also, note f
starts with lowercase and thus is not exported from the package main
. To access it in main_test
it needs to be exported (which can be done by changing it to start with a capital letter: F
).
Alternatively, you can change the test file to be in package main
.
Edit with a note: When importing main
note that import paths are by directory name. Usually developers in Go put their packages in directories with the same name as the package (e.g. put main
in a directory named main
). In your case the package and directory names are different so the import will be import ".../folder1"
not import ".../main"
. You'll still be able to use main.F()
to access the function:
package main_test
import (
"testing"
"../folder1" // use the full path to folder1 from the root of your module
)
func TestF(t *testing.T) {
main.F()
}