DEV Community

Discussion on: JUnit 5: link tests with task tracker issues

Collapse
 
nandorholozsnyak profile image
Nándor Holozsnyák

Hello there,

This is a really nice post, but this is missing to handle parameterized tests, I'm not sure if there is any other, in case of parameterized test the testId's pattern is the following:

[engine:junit-jupiter]/[class:org.example.SumTest]/[test-template:getSum(java.lang.Integer)]/[test-template-invocation:#1]
Enter fullscreen mode Exit fullscreen mode

It will include the invocation of the test, so you can determine which of the tests from the multiple is running, could be valuable, but for the report you might want to just put one method into the list not all, so in this case I replaced the Map with a new type, where the equals is overwritten so I can use the distinct of the stream.

It looks a bit weird, but for a quick try it will do:

final String method;
if (split[2].startsWith("[method:")) {
    // [method:testSum()] => testSum
    method = split[2].substring(8, split[2].length() - 1)
                     .replaceAll("\\(.*\\)", "");
} else {
    // [test-template:testSum(java.lang.Integer)] => testSum
    method = split[2].substring(15, split[2].length() - 1)
                     .replaceAll("\\(.*\\)", "");
}
Enter fullscreen mode Exit fullscreen mode

Btw, I was converting the JSON file to an AsciiDoc because I'm more into writing these, and I used JBang, as it has a maven plugin it can easily wired into the maven build and no other stack dependency is needed like NodeJS, but inside that it is at least easier to put together :D

Thank you for the post, this is a good one!

Collapse
 
kirekov profile image
Semyon Kirekov

Thank you very much for such a detailed response. I'll take into account the information about parameterized tests