-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: testing: Provide TestMain
with stats so that it can print a custom summary.
#41878
Comments
Perhaps we could instead give TestMain a way to get a list of the test functions, and have those functions report whether they succeed or fail. Then TestMain can do whatever it wants. |
I don't see how the proposed changes to If you write the summary out to a file and gather it at the end, you once again need a separate binary, so why not use the existing mechanism ( The crux of this argument seems to be
That statement seems a bit exaggerated to me. First lets look at the developer experience. An external binary does add a one-time step of downloading the binary, that's true, but after that one time the workflow is essentially unchanged. Compare running
There are optional Part of the argument seems to be that using another binary doesn't scale to larger teams. Any change to Finally there is the question of automation. Many of the largest open source Go projects are already using If so many of these large projects are already using an external binary, I would suggest it may not actually be a problem. I suspect these projects are using
So even if this proposal were implemented, it seems unlikely to be a replacement for the solution that already exists. |
I have another solution to this problem, that is a little unconventional. If you really don't want to install a different binary, you could use a library to run As an example, you could create a file in the project at package main
import (
"fmt"
"os"
"gotest.tools/gotestsum/cmd"
)
func main() {
name, args := os.Args[0], os.Args[1:]
args = append([]string{"-f=testname", "--"}, args...)
if err := cmd.Run(name, args); err != nil {
fmt.Fprintln(os.Stderr, "ERROR ", err.Error())
os.Exit(1)
}
} To run tests with a summary:
|
If we also provided it a list of examples and benchmarks, it could run those as well, controlling parallelism and setting b.N = 1, subsuming #41824. |
Please don't get me wrong on I partially agree with your second comment but I wouldn't run |
I would like to have access to the granular test results programmatically as well. I would like collect per-test telemetry for every invocation. Since I can't always control the invocation to use Looking at the testing package code, I think all the information I would need is readily available on the common struct. This could be exposed on
I think this would provide the same data as the original proposal, but allow for more extensibility. I think something like this is what @ianlancetaylor was suggesting as well. |
Background
There have been several requests in the past for a summary in the end of a test suite run:
All these requests have been denied as it isn't clear which summary style/format would clearly be beneficial.
The proposed workaround was to run the tests with
-json
and to use the output to generate a suitable summary.For instance gotestsum provides just that but it is an external tool and so developers and automation need to diverge from their usual workflow in order to utilize
gotestsum
.Proposal
Add test stats to
testing.M
so thatTestMain
can print a custom test results summary afterm.Run()
.The test stats should include:
This could be done by enhancing the
runTests
,runExamples
andrunBenchmarks
functions to produce these lists.All lists would be of type
[]InternalTest
,[]InternalExample
or[]InternalBenchmark
.The text was updated successfully, but these errors were encountered: