3

I'm using plunit package for my prolog unit tests (SWI-Prolog 7.2).

run_tests/0 prints the results on console but I would like to export plunit test results in the xUnit XML format that most CI servers understand. Is there any way for this ?

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
Koryonik
  • 2,728
  • 3
  • 22
  • 27
  • I don't know that format, but it should be easy to put such a thing together. Specifically, enter in the console listing(run_tests), and you can see all you'd need to do is replace that simple function (specifically the report/0 it uses) to get any output you want. – Alan Baljeu Feb 19 '16 at 05:47

1 Answers1

1

I assume that SWI-Prolog plunit tool uses the message printing mechanism to generate its output. If true, you should be able to export unit test results in the xUnit XML format (or any other format) by intercepting those messages using the message_hook/3 predicate:

http://www.swi-prolog.org/pldoc/doc_for?object=message_hook/3

By coincidence, I'm working in similar support (for exporting testing results) for Logtalk's unit testing tool, lgtunit. It should give you an idea on how to do it for plunit. I committed a preliminary version today:

https://github.com/LogtalkDotOrg/logtalk3/blob/master/tools/lgtunit/NOTES.md https://github.com/LogtalkDotOrg/logtalk3/blob/master/tools/lgtunit/xunit_xml_report.lgt

In my case, this support is being targeted for integration with the CI server Concourse. There seems to be, unfortunately, a lack of definitive information on the xUnit XML format with sources quoting different versions of e.g. which attributes are required or optional. I did find a XSD for this format bit I have no idea of its accuracy or if it's just another variation:

https://gist.github.com/erikd/4192748

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • Thanks, I just start coding a similar solution for SWI also. I would know if a lib was previously developed, but apparently no. Good Point for lgtunit, I also created a runner to run all logtalk test suites at once with a global report if interested. – Koryonik Feb 20 '16 at 16:59
  • @Koryonik Sure. Can you send it to me by mail? Thanks. Btw, you most likely know it already but you can also use `lgtunit` to test plain Prolog and Prolog module code. A good example is the Prolog conformance suite bundled with Logtalk. – Paulo Moura Feb 20 '16 at 17:25
  • See http://stackoverflow.com/questions/33475275/logtalk-what-is-the-best-way-to-run-all-test-suites/35528280#35528280, Code is shared. – Koryonik Feb 20 '16 at 19:57
  • @Koryonik Oops! I already have it on my clone of your repository. Sorry, too much going on. – Paulo Moura Feb 20 '16 at 20:41