-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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 a way to more easily test test utility #42827
Comments
A proposal is generally a very specific idea. This seems more like a vague problem statement, and I'm not understanding what solution you're proposing. |
I guess I tagged it wrong. I was trying to describe what features I wanted without locking down an implementation. I guess a more concrete proposal would be something like:
|
@jhenstridge would a better title for this issue be “provide a way to test Testmain functions” ? |
Perhaps related to #40984. |
@davecheney: the scope is a bit more than what a The concrete use case I have for this is go-check/check#122. I was trying to port go-check to use the stdlib test runner. While I was easily able to port the code over to using stdlib subtests, porting the tests has proved more difficult. These tests took the form of tests that create a new test runner that runs a collection of tests not part of the main test suite, and then inspecting the results. That kind of thing is all private in the stdlib testing framework. @ianlancetaylor: the suggestion in that bug report of using cleanup functions gets close to the first use case from my original post, with something like:
This would be enough to make the test fail if I'm not sure it would help out with the other two use cases I mentioned, where it is not clear how you'd check they worked directly from a test calling them. |
@jhenstridge, note that a test can invoke its own executable as a subprocess using the (See also #41980 (comment), #39903 (comment).) |
@bcmills: Thanks for the suggestion. I'll see if I can use that to adapt the tests I'm working on. Presumably something like this:
Hopefully the tests I actually want to keep can fit into environment variables + log inspection as the only communication needed. It would still be nice to have a more direct method of testing functionality like this. |
This is not a concrete proposal, and we just spent a lot of time discussing the topic on #40984. In the absence of a concrete proposal and to avoid duplicated effort, closing. |
@jhenstridge I've had success testing test helpers in https://github.com/gotestyourself/gotest.tools so I thought I would share in case it helps you. For the first two cases in the description I think the common practice is to have test helpers use a smaller interface instead of using "Check that a function spawns an expected set of subtests" is still difficult because As long as go-check doesn't expose |
For larger Go projects, it's common to write some utility functions or types for use in it's test suite. Ideally, those utilities should themselves be tested. However, there are certain types of behaviour that are difficult to test at present:
With most testing frameworks, the usual method to handle this would be to invoke the test runner with a custom set of tests, and then inspect the results. That's not really possible with Go's testing framework, since the method of constructing a test suite and invoking the runner is all private API (either inaccessible like
testing/internal/testdeps
, or documented to be unstable liketesting.TestMain
). Also, the runner depends on global state through flags that would be shared with the real test suite.The text was updated successfully, but these errors were encountered: