-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
testlib collections: Improve test names / assertion stack traces for collection test suites #7585
Comments
Maybe this really mostly affects Eclipse (where the user test class name does not seem to be shown), and not that much IntelliJ or Maven. So I could understand if you consider this not so important, or something Eclipse should improve. Though of course if there is an improvement from which all IDEs / tools could benefit, that would be great as well. |
Thanks. Reporting of this through our internal Bazel test runner is also not great, so I likewise end up searching for the value passed to It might end up being worth trying one of the quick options you suggested, though it might also get annoyingly complicated to do so while ensuring compatibility with Android and GWT/J2CL (which we test under internally to verify behavior in those environments). My guess is that it wouldn't actually be too hard, but that worry is what keeps me from running out to try something. Of course, the "right" solution is presumably for the testlib to be written in some style other than that of manual JUnit 3 suites.... |
Oh, I think I know why this problem seemed so weird to me and that I must be missing something. In the Gson samples, the test is returning the underlying Guava testlib suite directly. This relies on the reporter to decorate with the caller, which the JUnit 5 Eclipse runner will do and can execute v3/v4 tests. However, if you run using the JUnit 3 or 4 runners, per the Run Configuration, then you get only the suite's test name. Since you return Guava's directly, it does not include your own in the hierarchy. It's been a long time for me since the JUnit 3 days, but I believe it was pretty common to decorate suites to capture the class names at each nested level for debuggability. You could see if the following works for you, public static Test suite() {
var suite = new TestSuite(JsonArrayAsListSuiteTest.class.getSimpleName());
suite.addTest(istTestSuiteBuilder.using(new ListGenerator())...)
return suite;
} I suspect that Eclipse is defaulting to JUnit5 for me because my suite is a mixture of 3-5 (+ TestNG), so it picks up the dependency. JUnit 5 can run older suites using its test engines, so those being on the classpath allows Eclipse to run it fine even though the build uses the older runners directly due to JUnit5 being quite buggy and leaking memory, making it too unstable for anything but the simplest usages. |
Thanks, yes that is what I was thinking of as workaround, but the slight disadvantage is that this adds another layer of nesting in the test result UI. And usage of |
API(s)
com.google.common.collect.testing.*
For example
MapTestSuiteBuilder
orListTestSuiteBuilder
How do you want it to be improved?
The collection test suites should make it easier to identify where in the user code the test suite was created / to which user test class it belongs, especially if an assertion fails in the test suite
Why do we need it to be improved?
There are two issues with the collection test suites:
named(String)
, however if you specify(this differs between tooling / IDEs; in Eclipse there seems to be no indication which of the user's test classes created the test suite, in IntelliJ and Maven on console it does include the test class name in the UI / console output)
Example
Take for example this Maven test failure from Gson:
Or generally how the test suites are used in Gson:
JsonArrayAsListSuiteTest
JsonObjectAsMapSuiteTest
Current Behavior
Luckily Maven includes the name of the test Java class it is executing (in the example
JsonArrayAsListSuiteTest
), but besides that:com.google.common.collect.testing.testers.CollectionCreationTester.testCreateWithNull_unsupported
You would have to notice the test suite name (in the example "JsonArray#asList") and then manually look for the user test class which creates a test suite with that name.
Desired Behavior
See "How do you want it to be improved?" above
Not completely sure how it could be improved; some ideas:
createTestSuite()
and include its qualified class name in the test suite name (maybe?)That might be mostly relevant for Eclipse, see "Why do we need it to be improved?" above. Alternatively the user could do that themselves by creating an additional
TestSuite
with that qualified class name, wrapping the Guava test suite.createTestSuite()
and include it in the stack trace of assertion errors (possibly as dummy 'suppressed' or 'cause' exception)TestContainerGenerator
implementation and somehow include it in the test suite names or assertion errors (?)These ideas are not ideal; any other ideas are welcome!
Concrete Use Cases
See "Example" section above
Checklist
I agree to follow the code of conduct.
I have read and understood the contribution guidelines.
I have read and understood Guava's philosophy, and I strongly believe that this proposal aligns with it.
The text was updated successfully, but these errors were encountered: