gotestyourself / gotestsum

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.
Apache License 2.0
2.04k stars 121 forks source link

How to auto install #299

Open onattech opened 1 year ago

onattech commented 1 year ago

Hi, How can I get gotestsum to be a dependency in a project or get it auto installed. I don't want to tell the user to manually install it. Thank you

dnephin commented 1 year ago

Interesting question!

One option is something like this: https://play-with-go.dev/tools-as-dependencies_go119_en/. You can include it as an import in a project, but I guess that requires that someone run using go run gotest.tools/gotestsum, instead of simply gotestsum.

If you use a Makefile or some other tool for project tasks, you could include go install gotest.tools/gotestsum@latest to get it installed.

A third option, which is pretty unconventional, is something like #151, where you run go run ./test instead of go test, and that runs the tests with gotestsum.

onattech commented 1 year ago

Thank you for your reply. It turns out I am familiar with the first option. Gqlgen for graphql uses it. I'll probably go with the second option since there is a Makefile to install other dependencies.

dnephin commented 1 year ago

I learned about another option which should work like "auto install". You can run go tools like this without then being in the go.mod file:

go run gotest.tools/gotestsum@latest [gotestsum flags]

If the module already exists in $GOPATH/pkg/mod/... it will run it. It the source isn't available locally it will download the source, compile, and run.

gotestsum has very few dependencies, so it doesn't take long to download and compile on the fly like this.