I am trying to migrate my test suite from Junit4 to Junit5. Have a bunch of System Properties given as parameters in the older targets which run tests on Junit4 but now as i am migrating to Junit5, JunitLauncher doesn't support this parameter .
Older Target which runs tests on Junit4:
<target name="test">
<mkdir dir="${junit_reports.dir}" />
<junit printsummary="${junit.printsummary}" haltonfailure="${junit.haltonfailure}" haltonerror="${junit.haltonerror}" showoutput="${junit.showoutput}" fork="true" forkmode="once" failureProperty="failed">
<sysproperty key="clover.initstring" value="${clover.dbdir}/${clover.dbfile}" />
<sysproperty key="rules.location" value="${classes.dir}/rules/impl" />
<classpath>
<path refid="classes.classpath" />
<path refid="test.classpath" />
<pathelement path="${basedir}/../../.." />
<pathelement path="${test.classes.dir}" />
<path location="${basedir}/../common/target/test_classes" />
<pathelement location="${3rdparty.dir}/prime-server-framework/framework-core-mock.jar" />
</classpath>
<formatter type="${unittest.output.type}" />
<batchtest fork="true" todir="${junit_reports.dir}">
<fileset dir="${test.classes.dir}" includes="${tests.patternset}" />
</batchtest>
</junit>
</target>
New Target which runs tests on Junit5:
<target name = "sampletest">
<mkdir dir="${junit_reports.dir}" />
<junitlauncher>
<classpath>
<path refid="classes.classpath" />
<path refid="test.classpath" />
<pathelement path="${basedir}/../../.." />
<pathelement path="${test.classes.dir}" />
<path location="${basedir}/../common/target/test_classes" />
</classpath>
<!--<testclasses outputdir="${junit_reports.dir}">
<fileset dir="${test.classes.dir}">
<include name = "**/*Test.class"/>
</fileset>
</testclasses>-->
<test name = "impl.RulesEngineValidationTest"/>
</junitlauncher>
</target>
How do i give system properties in new target?
Ant 1.10.4 does support JUnit 5. However, it does not support all the features that Ant integration JUnit 4 does. In particular, it does not support forking the junit process and therefore passing system properties.
I found this question because I was trying to do the same thing. I found a workaround though. You can set the system properties in code before calling junitlauncher.
This code is what I used to set a single system property for file encoding. You could do something similar for your properties.
<script language="javascript">
<![CDATA[
var imports = new JavaImporter(java.lang.System);
imports.System.setProperty('file.encoding', 'ISO8859_1')
]]>
</script>
Yours is a little more complicated since your properties use others. You can read an Ant variable from inside the code. (I don't know how to read one with a dot in the name so I got rid of the dot in this example)
<property name="cloverdbdir" value="clover-dir-property-value" />
<property name="cloverdbfile" value="clover-db-file-property-value" />
<script language="javascript">
<![CDATA[
var imports = new JavaImporter(java.lang.System);
imports.System.setProperty('clover.initstring', cloverdbdir + '/' + cloverdbfile);
print(imports.System.getProperty('clover.initstring'));
]]>
</script>
There are a few things to be aware of if you use this technique:
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