I maintain a library that our larger org uses for its ant configuration files. I am trying to update from a junit 4 backend to junit 5 backend with minimal disruption to end users.
The main issue I am running into is output formatters. We have a macrodef that accepts a <element name="test-formatter"/>
that is used like
<runmultipletest foo=...>
<test-formatter>
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
</test-formatter>
<runmultipletest-fileset>
<fileset refid="${junit.integration.fileset}"/>
</runmultipletest-fileset>
</runmultipletest>
inside the macrodef this was fed into
<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
<test-formatter/>
<runmultipletest-fileset/>
</batchtest>
Now I am upgrading to junit 5. Is it possible without breaking backward compatibility with the existing format end users use to transform the
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
into
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
<listener type="legacy-xml" sendSysErr="true" sendSysOut="true" outputDir="@{test.todir}"/>
from inside my macrodef? I can figure out the XSLT to transform the xml in to what I want but I don't know Ant well enough to know if it is possible to transform the passed in element and then have junitlauncher
use it.
Well, it's unclear to me how you switch from JUnit 4
to JUnit 5
, anyway you could be able to pass a parameter to the macrodef
in order to change the content of test-formatter
, like the following:
<macrodef name="test-formatter">
<attribute name="version" />
<sequential>
<if>
<equals arg1="@{version}" arg2="5" />
<then>
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
<listener type="legacy-xml" sendSysErr="true" sendSysOut="true" outputDir="@{test.todir}"/>
</then>
<else>
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
</else>
</if>
</sequential>
</macrodef>
So when you execute the tests you can choose which test-formatter use:
<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
<test-formatter />
<runmultipletest-fileset />
</batchtest>
rather than:
<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
<test-formatter version="5" />
<runmultipletest-fileset />
</batchtest>
If I'm right and you already have an attribute that holds the JUnit
version you can pass it as parameter to the test-formatter
as discuss above.
I hope it helps you, bye.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With