Are functions on struct defined in a test file visible in other projects?

32 views Asked by At

I am using "github.com/stretchr/testify/suite" to create a testsuite, the suite definition is present in a helper file B. The suite has some functions defined for it in the file A, which also happens to have test in the file name. Both of these belong in the same package. I am importing this package in another unrelated project C, should the functions defined on the suite struct inside the file A be visible in C? I have made sure that they start with capital letter so that they are exported. The functions defined in B are visible in the project C. So only issue that I am having is that the functions defined in the test file A are not visible in C. Is there a reason behind this or have I made a mistake.

For example: A = helper_test.go B = hepler.go B contains a testsuite HelperSuite. It has some functions defined for the struct in it, say, BFileFunc(). A also has some functions defined for the struct in it, say, AFileFunc(). This package is being imported in a completely unrelated project C, wherein I find that I am able to call BFileFunc() for a suite instance, but not AFileFunc(). Is this supposed to happen? Notice that both the function names start with capitals, which I have checked in my code as well.

1

There are 1 answers

0
Volker On

Are functions defined in a test file visible in other projects?

No.

And there is no way "around" that. If you want to share code you must put it into (the actual code of) a package (and export it).