Let's say I have a test helper function that does either some setup or some assertions. That is: it is a function that has reusable unit testing code. I want to be able to have it in a place where I can call it from two different packages' unit tests.
However, Go does not provide visibility for exported functions in *_test.go
files.
One alternative is to have it in a file that is not named in such pattern. That way it should behave just like a normal exported function, but the downside is that then it is actually going to be considered as application code, meaning we would have to even write unit tests for it in order to not mess with the project's code coverage.
So what is the best way to deal with reusable unit testing functions in Go?
Aucun commentaire:
Enregistrer un commentaire