更新到junit 5时保持build.xml的语法兼容性

Sco*_*ain 5 java ant junit junit4 junit5

我维护一个库,我们的大型组织将其用于其ant配置文件。我正在尝试从junit 4后端更新到junit 5后端,同时对最终用户的干扰最小。

我遇到的主要问题是输出格式化程序。我们有一个macrodef,它接受<element name="test-formatter"/>

<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>
Run Code Online (Sandbox Code Playgroud)

在宏定义内部

<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
    <test-formatter/>
    <runmultipletest-fileset/>
</batchtest>
Run Code Online (Sandbox Code Playgroud)

现在我要升级到junit5。在不破坏与最终用户用于转换现有格式的现有格式的向后兼容性的情况下

<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
Run Code Online (Sandbox Code Playgroud)

进入

<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
<listener type="legacy-xml" sendSysErr="true" sendSysOut="true" outputDir="@{test.todir}"/>
Run Code Online (Sandbox Code Playgroud)

从我的macrodef内部?我可以弄清楚XSLT可以将xml转换成我想要的格式,但是我对Ant的了解还不够,无法知道是否可以转换传入的元素然后再junitlauncher使用它。

Ale*_*dro 1

好吧,我不清楚如何从 切换JUnit 4JUnit 5,无论如何,您可以将参数传递给macrodef来更改 的内容test-formatter,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

因此,当您执行测试时,您可以选择使用哪个测试格式化程序:

<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
    <test-formatter />
    <runmultipletest-fileset />
</batchtest>
Run Code Online (Sandbox Code Playgroud)

而不是:

<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
    <test-formatter version="5" />
    <runmultipletest-fileset />
</batchtest>
Run Code Online (Sandbox Code Playgroud)

如果我是对的并且您已经有一个保存版本的属性,JUnit您可以将其作为参数传递给test-formatter上面讨论的。

希望对你有帮助,再见。