Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

How to get test case names in output

Open pwinston opened this issue 5 years ago • 9 comments

I expected one output option would be like this:

MyTestCase1: 5 assertions passed
MyTestCase2: 3 assertions passed
...

or even just

MyTestCase1: PASS
MyTestCase2: PASS
....

I figured the log should list the tests that were performed, not just "passed 182 test cases" since that doesn't tell you what tests were in place at the time.

I see the junit and xml reporters to include the test case names. Are there settings that produce a simple list like above? Or is it necessary to transform the xml, or write a reporter? Or is this not a useful output format to ask for for some reason?

pwinston avatar Mar 23 '19 02:03 pwinston

I guess this is pretty close ./runner --list-test-names-only || ./runner but still wondering if there is something like I'm saying, with each test case name followed by the result.

pwinston avatar Mar 23 '19 02:03 pwinston

If you want your output to contain passed assertions, you can try the -s flag. However, having successful tests be a part of the output leads to an unreadable mess fairly quickly -- I would consider the test suite at my current employer fairly modest, but the summary line is

Passed all 3889 test cases with 28179 assertions.

so having a line per test case would make console output pretty unusable.

If you want your own bespoke output format, then that's what the Reporter interface is for.

horenmar avatar Mar 24 '19 21:03 horenmar

Thanks for the response. I think -s is too much information, that's essentially echoing lines of code, where the test names are hand-chosen and presumably human readable.

I see your point about having 4,000 tests, but put yourself in the shoes of a new user with 20 tests: seeing the test names printed seems reasonable to me. From what I see of Google Test docs they print test names in their default output, I didn't install google test, but it looked that way.

I'm not going to press the issue. Just giving the feedback that as a new user I felt 100% sure this type of output must be available in the system, it just seemed logical to me, and spent a long time looking for it. We'll probably just do --list-test-names-only as a way to record what tests were run, I think that's sufficient for our needs so that's good.

pwinston avatar Mar 25 '19 17:03 pwinston

+1 to have names of running tests printed as a non-default option.

biodranik avatar Dec 01 '19 21:12 biodranik

This can be done now as a side effect of passing -d yes:

root@microzed-zynq7 ~ ./unittests -d yes
0.000 s: Can instantiate Thing
0.000 s: Structs are the right size
===============================================================================
All tests passed (12 assertions in 2 test cases)

codypiersall avatar Apr 24 '20 21:04 codypiersall

Suppose one of your tests terminates the whole process, but you don't know which test does that. Then, it would be helpful to have the name of each test printed before attempting to run it. The -d yes workaround prints test names after executing them, so it would print the last-successfully-executed test, rather than the name of the test that terminates the process. Often, the test in question comes right after the last-successfully-executed test, but some tests might be hidden, and the test that happens to terminate the process might be the very first test in its C++ translation unit. So, it would be nice to add to console runner a command-line option that causes the names of the tests to be printed just before executing them.

guban avatar Dec 01 '21 16:12 guban

-d yes also gets difficult to interpret when there are nested sections within the tests. Not a viable workaround for this issue for my current projects unfortunately. The simple test-name-delineated output that the OP describes would be very helpful to have as a bundled option.

sketch34 avatar Aug 10 '22 07:08 sketch34

I can't wrap my head around the fact that this is not implemented. I understand the default decision due to brevity of testing report, but why not make it optional? Genuinely confused a bit lol

xade93 avatar Feb 13 '24 03:02 xade93

+1 would definitely be an excellent addition to the otherwise great library Catch2!

JanGaertner avatar Feb 13 '24 12:02 JanGaertner