Skip to content

JUnit5 DynamicContainer are not working #1617

Closed

Description

With this test

@TestFactory
public Stream<DynamicContainer> testContainers() {
  return Stream.of(dynamicContainer("Container", List.of(
    dynamicTest("Test", () -> {assertTrue(false);})
  )));
}

Gradle outputs the result, but VSCode runs the test and reports just an empty bullet, not picking the failure.

Activity

  1. jdneo commented on Sep 29, 2023

    @jdneo
    Member

    Thank you for reporting this bug.

    Though it's not related with #1603, but this reflects some 'bad' design/implementation when handling the invocation/dynamic tests.

    Some refactoring is needed.

  2. changed the title [-]JUnit5 DynamicContainer are not wokring[/-] [+]JUnit5 DynamicContainer are not working[/+] on Sep 29, 2023
  3. added this to the 0.41.0 milestone on Sep 29, 2023
  4. jdneo commented on Sep 29, 2023

    @jdneo
    Member

    Please use this private build to unblock yourself:
    vscode-java-test-0.40.2023092907.vsix.zip

    The PR still needs more days (~ 1 week) to be merged due to the holiday here. If you find any issue using the private bit, please let me know.

  5. mapio commented on Oct 9, 2023

    @mapio
    Author

    I've tested it. It's true that now tests in a container are picked up. But test reports do not show any form of hierarchy.

    According to this post for example it should go from flat to tree-like.

  6. jdneo commented on Oct 9, 2023

    @jdneo
    Member

    What did you see from your side?

    image

  7. mapio commented on Oct 9, 2023

    @mapio
    Author

    I'm sorry but I can't reproduce the example of the Medium post.

    With this code:

    import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
    import static org.junit.jupiter.api.DynamicTest.dynamicTest;
    
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.List;
    
    import org.junit.jupiter.api.DynamicContainer;
    import org.junit.jupiter.api.TestFactory;
    
    public class TestContainers {
    
    	@TestFactory
    	Collection<DynamicContainer> testContainer() {
        List<DynamicContainer> containers = new ArrayList<>();
        containers.add(
          dynamicContainer("First Container", List.of(
            dynamicTest("First test of first container", () -> {}),
            dynamicTest("Second test of first container", () -> {})
          ))
        );
        containers.add(
          dynamicContainer("Second Container", List.of(
            dynamicTest("First test of second container", () -> {}),
            dynamicTest("Second test of second container", () -> {})
          ))
        );
        return containers;
      }
    }
    

    I get

    TestContainers > testContainer() > First Container > TestContainers.First test of first container PASSED
    TestContainers > testContainer() > First Container > TestContainers.Second test of first container PASSED
    TestContainers > testContainer() > Second Container > TestContainers.First test of second container PASSED
    TestContainers > testContainer() > Second Container > TestContainers.Second test of second container PASSED
    

    as gradle testoutput, but this in the sidebar

    image

    So apparently the two containers are there, but are not viewable.

  8. mapio commented on Oct 9, 2023

    @mapio
    Author

    Ahah, my fault. I was looking at the "Testing result" panel, not at the testing sidebar. There the containers show up!

    image

    So now the question is: why the UI of the panel and sidebar are different?

  9. jdneo commented on Oct 10, 2023

    @jdneo
    Member

    My understanding is that the Test Explorer (sidebar) is used to show all the tests in the workspace. While the Test Result (panel) is used to show the tests of each execution.

    We have an issue about improve the Test Result content: #1588

  10. mapio commented on Oct 10, 2023

    @mapio
    Author

    The explanation makes a lot of sense! Thank you for referring me to the other issue. You are very helpful, thank you for your time and work!

  11. mapio commented on Sep 29, 2025

    @mapio
    Author

    I think we have a regression.

    Since last update (using Java 25). In the testing panel first the > indicating the presence of an hierarchy of results appears for a few seconds and then the panel re-draws and the hierarchy disappears.

    No errors in the console, non failed tests in the testing result panel. At the end you get:

    Image

    But as you can see, the side panel "reloads" somehow loosing the hierarchy information.

    Screencast.from.2025-09-29.09-46-54.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions