-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Run test case N times with N different inputs #558
Comments
My solution for now is to wrap the stuff I'm doing in a lambda, with only assertion and logging macros inside (no TEST_CASE macros) and then call that lambda repeatedly in one or more TEST_CASE blocks with different parameters. It is still awkward (especially since the setup has to be performed, one way or another, inside the lambda) but it works. |
This feature is called Generators and is something I've had on a the back-burner for a while. I've recently been working on it again a bit more - but it's still a little way off being ready. |
Any update on this, @philsquared? |
I am also interested in this. Sometimes this is called data-driven testing (DDT), e.g., in Qt's test framework, or Value-parameterized testing in Google Test. |
👍 This would be especially useful for testing numerical code, like the one I'm working on. For example, I have slightly different data for each test run. I could write a loop around one 'REQUIRE', but for 'SECTION's or 'TEST_CASE's this does not work apparently. |
A little update on this:
So, in summary, it's all still coming - but still not for a while yet, I'm afraid. |
Second this. What is the status of Catch2 @philsquared ? |
At time of writing Catch2 is on hold until the Catch "classic" backlog is under control. |
I believe I have answered this query now (even if not entirely satisfactorily) - and objection to me closing it? (@capsocrates, if you're still watching?) |
I'm ok with closing it, but I'd appreciate a ping here when Catch2 hits the streets with this feature. |
I'm closing this in favour of #850, so be sure to watch that issue for notifications. |
I realize this is closed, but I'd like to reply to one particular comment made above by @roversch who said it's not possible to put a We're doing exactly this, and seems to work well for us:
This works so well that I'm actually not sure what the excitement about data-driven tests is about. What am I missing? (The only slightly annoying thing here is having to manually construct the section names. In this particular example it's easy enough, but often we loop over enum constants, and there's no elegant solution to stringify these.) |
Thanks @stefanhaller ! I'll try it out again. It's been a while, so I forgot what exactly went wrong. |
I think it's worth commenting here that if you do use a SECTION inside a loop, make sure it has a unique name for each iteration of the loop. If you don't use unique names then some tests will be ignored and you might miss failures. |
Sometimes I want to repeat a test a number of times, but with one (or more) values changed each time. If I try to wrap a TEST_CASE inside a for loop, the for loop just executes on its own before the TEST_CASE executes.
E.g.
I recognize that a for loop might not jive with the implementation of the TEST_CASEs, but it would be nice to have some built-in feature that allows Catch to run the same test over again just with different inputs/setups.
As an extension to that, it would be nice to have a feature that allowed running a TEST_CASE repeatedly with different combinations of inputs, for instance, given inputs
The text was updated successfully, but these errors were encountered: