vendredi 27 janvier 2017

How can I share setup and teardown methods across packages when testing Go?

Let's say I have two packages foo and bar. Each package has file and a test file:

foo
---widget.go
---widget_test.go
bar
---wingding.go
---wingding_test.go

Now for both tests (widget_test.go and wingding_test.go) I want to share some setup code. I know I can put this code inside each package inside main_test.go. But I obviously don't want to copy/paste code in two places. So where can I put this code so that it's shared across packages?

Aucun commentaire:

Enregistrer un commentaire