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

Don't show children for JUnit 5 @TestTemplate tests that ran only once #1217

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

iloveeclipse
Copy link
Member

@iloveeclipse iloveeclipse commented Feb 19, 2024

Don't show children for JUnit 5 @TestTemplate tests that ran only once

When running JUnit 5 @TestTemplate tests, extra test suites are shown in the JUnit view to represent the tests in the template. Those suites introduce unnecessary noise when the template contains only one test - e.g. when repeating tests that failed.

This change adjusts TestSuiteElement.getChildren(), pruning each TestSuiteElement that has a single TestCaseElement child that is also a dynamic test.

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Assume;
import org.junit.jupiter.api.MethodOrderer.MethodName;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

@TestMethodOrder(MethodName.class)
public class TestTemplatesJunit5 {

	@Test
	public void testOkNoRepeats() throws Exception {
		Thread.sleep(500);
	}
	
	@RepeatedTest(value = 1)
	public void testOkOneRepeat() throws Exception {
		Thread.sleep(500);
	}

	@RepeatedTest(value = 2)
	public void testOkTwoRepeats() throws Exception {
		Thread.sleep(500);
	}
	
	@Test
	public void testWithErrorNoRepeats() throws Exception {
		doStupidThings(null);
	}
	
	@RepeatedTest(value = 1)
	public void testErrorOneRepeat() throws Exception {
		doStupidThings(null);
	}
	
	@RepeatedTest(value = 2)
	public void testErrorTwoRepeats() throws Exception {
		doStupidThings(null);
	}

	@Test
	public void testFailNoRepeats() throws Exception {
		assertEquals("expected", "observed");
	}
	
	@RepeatedTest(value = 1)
	public void testFailOneRepeat() throws Exception {
		assertEquals("expected", "observed");
	}

	@RepeatedTest(value = 2)
	public void testFailTwoRepeats() throws Exception {
		assertEquals("expected", "observed");
	}


	@RepeatedTest(value = 0)
	public void testWrongRepeat() throws Exception {
		Thread.sleep(500);
	}
	
	@Test
	public void testAssume() throws Exception {
		Assume.assumeFalse(true);
	}
	
	@RepeatedTest(value = 1)
	public void testAssumeOneRepeat() throws Exception {
		Assume.assumeFalse(true);
	}
	
	@RepeatedTest(value = 2)
	public void testAssumeTwoRepeats() throws Exception {
		Assume.assumeFalse(true);
	}
	
	private void doStupidThings(String arg) {
		arg.toString();
	}
	
}

Fixes #945

@trancexpress
Copy link
Contributor

trancexpress commented Feb 19, 2024

@iloveeclipse I would rather not have changes like this all over the view and model code. Better to revert and we'll adapt our use case to not have the problem in the first place.

There are also more problems that remain not adressed, such as the test count not being displayed properly. Or the view collapsing after each test, instead of showing proper expanded state. We are better off without the templated tests in our IDE, support for them is not good in multiple ways.

@iloveeclipse
Copy link
Member Author

After merging revert in #1203 for RC1 the plan is to "revert the revert" & add this patch on top for 4.31 M1.

@iloveeclipse iloveeclipse changed the title JUnit view issues with "templated" tests Don't show children for JUnit 5 @TestTemplate tests that ran only once Feb 20, 2024
When running JUnit 5 @testtemplate tests, extra test suites are shown in
the JUnit view to represent the tests in the template. Those suites
introduce unnecessary noise when the template contains only one test -
e.g. when repeating tests that failed.

This change adjusts TestSuiteElement.getChildren(), pruning each
TestSuiteElement that has a single TestCaseElement child that is also a
dynamic test.

Fixes eclipse-jdt#945
@iloveeclipse iloveeclipse merged commit 10d2f66 into eclipse-jdt:master Mar 29, 2024
9 checks passed
@iloveeclipse iloveeclipse deleted the repeated_fix branch March 29, 2024 09:22
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.

Dont show children for JUnit 5 @TestTemplate tests that ran only once
2 participants