linkrope / dunit

xUnit Testing Framework for D
Boost Software License 1.0
37 stars 9 forks source link

SonarQube generic execution reporter #24

Open andre2007 opened 5 years ago

andre2007 commented 5 years ago

SonarQube has a generic test execution report format [1]

<testExecutions version="1">
  <file path="testx/ClassOneTest.xoo">
    <testCase name="test1" duration="5"/>
    <testCase name="test2" duration="500">
      <skipped message="short message">other</skipped>
    </testCase>
    <testCase name="test3" duration="100">
      <failure message="short">stacktrace</failure>
    </testCase>
    <testCase name="test4" duration="500">
      <error message="short">stacktrace</error>
    </testCase>
  </file>
</testExecutions>

If d-unit could also produce a report in this format, the results can directly be imported into SonarQube.

PS. At the moment SonarQube fails if in attribute "path" a file with extension ".d" is specified. I opened a ticket on SonarQube, they will fix this issue.

[1] https://docs.sonarqube.org/latest/analysis/generic-test/

andre2007 commented 5 years ago

To get the filepath the mixin can be enhanced like this

mixin template UnitTest(string filename = __FILE__)

(Thanks to Exil from forum.dlang.org for this tip)

andre2007 commented 5 years ago

It seems it is not possible to get the filename for D unittests ): ModuleInfo does not contain this info.

andre2007 commented 5 years ago

There is a pr which will add a new __traits to determine the file location of a given symbol: https://github.com/dlang/dmd/pull/10013

andre2007 commented 4 years ago

PR was merged and new __traits getloc is available: https://dlang.org/changelog/2.088.0.html#getloc