Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping syntax compatibility of build.xml while updating to junit 5

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.

like image 981
Scott Chamberlain Avatar asked Nov 07 '22 15:11

Scott Chamberlain


1 Answers

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.

like image 156
Alessandro Avatar answered Nov 14 '22 22:11

Alessandro