-
Notifications
You must be signed in to change notification settings - Fork 108
Include the location of a parameterized test argument which recorded an issue (if possible) in console output for better traceability #1037
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
Comments
We intentionally don't include an integer index because we cannot reliably determine them at runtime for all collection types, and cannot reliably determine if a given collection type has stable indexing. Improvements to test case enumeration are currently tracked by #671. |
And I'm pleased to report that one subtask of that, #1000, recently landed and provides a mechanism to distinguish test case IDs. That being said, I think neither #671 nor #1000 will truly address the complaint here. It seems to me that the basic problem is that when a test case for a parameterized test argument records an issue, it can be difficult to trace back to the location in source where that argument was defined. #1000 can help address that issue, but won't solve it on its own. I think we should find a way to capture more information about the source and location of test arguments so that in the results we could actually note the source location where the argument was passed. That, to me, would be even more powerful than including each arguments' index in the collection; an index is just an indirect way to refer to an element, but if you can jump directly to the location of that element in source code, all the better. (This all assumes that a collection literal is being passed to |
@Test(arguments:)
for better traceability
Ah, here we go: this can actually be considered a dupe of a different issue: #519. |
Thanks for the detailed explanation! |
That's a better original, thanks :) |
Uh oh!
There was an error while loading. Please reload this page.
Motivation
When using
@Test(arguments:)
to test multiple input patterns in a single test function, it can be difficult to identify which argument caused a failure, especially when several similar test cases are used.For example, consider the following test setup:
Supporting code:
Test code:
When a test fails, the output looks like this:
However, this output alone doesn’t clearly indicate which argument (i.e., which entry in the
arguments
array) caused the failure. This makes it difficult to trace which case needs to be fixed, especially in large or complex test sets.Proposed solution
A helpful enhancement would be to include the argument’s index in the failure output. For example, if the second item in the arguments array fails, the output might look like this:
This small addition would make it significantly easier to identify the failing case and improve the debugging experience, especially when dealing with multiple test arguments.
Currently, developers can work around this by wrapping the argument in a custom struct with a label, like so:
While this pattern works, it adds boilerplate and isn’t ideal for simpler test cases.
Including the argument index in the default output would be a lightweight and widely useful improvement that benefits many test scenarios.
Alternatives considered
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: