Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: get the valid test results (coverage data) from an ant-bulid test run via "@RunWith(Parameterized.class)". Further informations can be found in the separate project "clover-examples/parameterized-junit4-example". #243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

udoline
Copy link

@udoline udoline commented Feb 13, 2024

No description provided.

ant-bulid test run via "@RunWith(Parameterized.class)". Further
informations can be found in the separate project
"clover-examples/parameterized-junit4-example".
@udoline
Copy link
Author

udoline commented Feb 14, 2024

Here is a sample, how it will be using

<target name="runUnitParamterizedTestBatch"  depends="check.tns.admin, compileTests, runTests.init" if="clover.active"
	description="workaround: detecting correct coverage data via openclover-4.5.1 during paramterized test executions">
	<property name="junit.unittest.module.name" value="required" />
	<property name="junit.unittest.selector" value="required" />
	<property name="junit.unittest.forkmode" value="once" />
	<property name="junit.unittest.timeout" value="240" />
	<property name="junit.unittest.maxmemory" value="334m" />
	<junit fork="yes" forkmode="${junit.unittest.forkmode}" timeout="${junit.unittest.timeout}" maxmemory="${junit.unittest.maxmemory}" 
		   showoutput="yes" printsummary="on" haltonfailure="false" haltonerror="false" failureproperty="tests.failures" errorproperty="tests.errors">
		   
		<formatter type="xml">
		<!-- customized junit formatter -->
		<formatter classname="org.openclover.ant.taskdefs.optional.junit.CloverJUnitResultFormatter"/>

		<batchtest todir="${dir.report.junit}">
			<fileset dir="${dir.up}/${junit.unittest.module.name}/${dir.src.test}">
				<selector refid="${junit.unittest.selector}" />
			</fileset>
		</batchtest>
	</junit>
</target>

@marek-parfianowicz
Copy link
Member

Thank you for your contribution. I'm working on one large refactoring task in OpenClover, once I finish it, probably in a week or two, I will review your changes.


if (null != testNameSniffer) {
if (start) {
testNameSniffer.setTestName(JUnitVersionHelper.getTestCaseName(test));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cold you please explain why do you want to use the JUnit formatter feature to inject name of a test being executed into OpenClover's runtime? I'm asking because OpenClover already supports parameterized tests (JUnit 4, Spock).

Copy link
Author

@udoline udoline Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no motivation to introduce another dependency in an outdated Java project.
In this very large, complex Java project (web app), countless technical or buisness functions are implemented with many dependencies.
I have currently put together a workaround via Java reflection, which calls the two Java classes

//  583 2023-10-29 18:10 com_atlassian_clover/TestNameSniffer.class
// 2273 2023-10-29 18:10 com/atlassian/clover/recorder/TestNameSnifferHelper.class

in the Junit4 test runtime in Jenkins-Job "Git Develop Nightly" to generate correct Clover coverage data.

The error | problem:
If this is not done, 0% coverage will be displayed in the application Java class (src/main/java).
However, in the executed test Java class it is visible that the application Java class has been loaded and parts executed.
Furthermore, the execution dates of the parameter pairs are not listed either.

The solution "CloverJUnitResultFormatter" implements this functionality without Java reflection.

The feature of easy configuration via Ant build.xml convinced me to make it public.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your spock-example is outdated. Won't works properly with openclover 4.5.2 😒
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants