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

Support alteration of discovered tests #276

Closed
smoyer64 opened this issue May 23, 2016 · 3 comments
Closed

Support alteration of discovered tests #276

smoyer64 opened this issue May 23, 2016 · 3 comments

Comments

@smoyer64
Copy link
Contributor

I'm not sure that's a great description of what I want to ask ... in #153 the following code is discussed:

package org.example;

public class TopLevel {

    static class StaticNested {}

    @Nested
    class Inner {}

    @Test
    void method1() {}

    @Test
    void method2(TestInfo testInfo) {}

    @TestFactory
    Stream<DynamicTest> dynamicTests() {
        return Stream.of(new DynamicTest("dynamic test", () -> {}));
    }

}

Maybe I'm missing something but it looks like @testfactory can only add tests to an existing test plan. In order to support repeating parameterized test methods, there needs to be a mechanism to alter previously discovered tests (in essence, turning them into test containers).

While I love that a @testfactory can creates completely dynamic tests, there's a pattern that's common to JUnit4 test runners that I think is also important. I'll use the JUnitParams extension (one of my favorites) as an example - the generic code for a test would be something like this:

@RunWith(JUnitParamsRunner.class)
public void SomeTest {

  @Test
  @Parameter("1", "2", "3")
  public void testThatSomethingHappens(int someParameterThatMatter) {
    ...
  }

}

The above JUnitParams test class would result in three tests being executed. If I run that test today using JUnit4, it will use the test name as the container name and add the values of the parameters to the enclosed tests. I don't see how the equivalent pattern could be realized with JUnit5 (obviously, I'm not an expert in the code yet).

From the digging I did into the ALPHA release, I was picturing the addition of something like a test discovery callback that could be called after each @test was found (or for each DynamicTest returned by a @testfactory?). And during discovery, these test would have to be mutable so they could be expanded.

Am I missing something obvious? How would the @junit-team/junit5 developers suggest coding this pattern?

@smoyer64
Copy link
Contributor Author

I see that as a result of #271, a CompositeTestSource was created. This looks like it provides the required hierarchy described in my problem statement above, so I guess the real question is how to "discover" a test like the JUnitParams example above.

@smoyer64
Copy link
Contributor Author

Issue #354 provides a PoC that resolves this issue.

@marcphilipp
Copy link
Member

This has been superseded by test templates.

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