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

Cannot exclude specific invocations from Filter #153

Open
marcphilipp opened this issue Mar 30, 2018 · 1 comment
Open

Cannot exclude specific invocations from Filter #153

marcphilipp opened this issue Mar 30, 2018 · 1 comment

Comments

@marcphilipp
Copy link

A Filter that is applied to a JUnitParamsRunner gets passed different Description instances than the runner actually uses.

Example

Running the main method from the following example demonstrates the issue.

@RunWith(JUnitParamsRunner.class)
public class JUnitParamsTestCase {
	@Test
	@Parameters({ "17, false", "22, true" })
	public void personIsAdult(int age, boolean valid) {
	}

	public static void main(String... args) throws Exception {

		Runner runner = Request.aClass(JUnitParamsTestCase.class).getRunner();

		System.out.println("Full Description:");
		printRecursively(runner.getDescription(), "");
		System.out.println();

		System.out.println("Filtering:");
		Filter filter = new Filter() {
			@Override
			public boolean shouldRun(Description description) {
				System.out.println("shouldRun? description=" + description + ", children=" + description.getChildren());
				return !description.getDisplayName().contains("17, false");
			}

			@Override
			public String describe() {
				return "exclude everything";
			}
		};
		filter.apply(runner);
		System.out.println();

		System.out.println("Running:");
		JUnitCore core = new JUnitCore();
		core.addListener(new RunListener() {
			@Override
			public void testFinished(Description description) {
				System.out.println("finished: " + description);
			}
		});
		core.run(runner);
	}

	private static void printRecursively(Description description, String indent) {
		System.out.println(indent + "- " + description);
		description.getChildren().forEach(c -> printRecursively(c, indent + "  "));
	}
}

Output

Full Description:
- org.junit.vintage.engine.samples.junit4.JUnitParamsTestCase
  - personIsAdult
    - personIsAdult(17, false) [0](org.junit.vintage.engine.samples.junit4.JUnitParamsTestCase)
    - personIsAdult(22, true) [1](org.junit.vintage.engine.samples.junit4.JUnitParamsTestCase)

Filtering:
shouldRun? description=personIsAdult(org.junit.vintage.engine.samples.junit4.JUnitParamsTestCase), children=[]
shouldRun? description=personIsAdult(org.junit.vintage.engine.samples.junit4.JUnitParamsTestCase), children=[]

Running:
finished: personIsAdult(17, false) [0](org.junit.vintage.engine.samples.junit4.JUnitParamsTestCase)
finished: personIsAdult(22, true) [1](org.junit.vintage.engine.samples.junit4.JUnitParamsTestCase)

Actual Behavior

The Description instances passed to the Filter are generated by describeChild and contain no children and no information about the parameters being used. Thus, it's impossible to exclude them based on this information.

Expected Behavior

The Filter receives the same Description instances used as direct children of the Description returned by JUnitParamsRunner.getDescription().

Potentially Related Issues

@mmorrisontx
Copy link

If anyone else hits this problem in the future, I can confirm that the patch in #123 does actually solve the problem.

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

No branches or pull requests

2 participants