Repository navigation
Good naming scheme for test derived artifacts (screenshots) #2936
Replies: 1 comment
|
I would use JUnit's unique ID as the canonical identity rather than constructing an identity from class name + method name. For example: String uniqueId = context.getUniqueId();
String displayName = context.getDisplayName();The display name is useful for humans, but it should not be the unique part of the filename: parameterized/dynamic tests can have duplicate display names and characters that are inconvenient in file paths. A practical naming scheme is therefore: where the JUnit unique ID is what guarantees that the artifact can be traced back to the particular test invocation. On current JUnit there is an even better option if your reporting infrastructure supports attachments: publish the screenshot directly against the current test/container instead of encoding its identity into the filename: context.publishFile(
"failure.png",
MediaType.IMAGE_PNG,
path -> Files.write(path, screenshotBytes)
);with: import org.junit.jupiter.api.MediaType;JUnit then associates the file with the current test or container. One caveat for your mention of dynamic tests: if the extension currently takes failure screenshots through If you need uniform handling of dynamically registered tests too, a JUnit Platform So for filesystem naming, use the JUnit unique ID; where possible on modern JUnit, prefer publishing the artifact directly against the test. Please mark this answer as accepted if it helped, thank you. |
Uh oh!
There was an error while loading. Please reload this page.
I was working on an extension that takes screenshots of failed tests. Right now the naming scheme of the screenshot files is roughly this:
context.getRequiredTestClass().getName() + "_" + context.getRequiredTestMethod().getName() +someExtensionHowever, given there might be parameterized tests, dynamic tests etc. this is probably not sufficient in some cases. I guess that others had to solve the "create a name for an artifact that can traced back to the test that created it" problem before me, so I'm wondering if someone can recommend a better naming scheme?
All reactions