microsoft / vscode-java-test

Run and debug Java test cases in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test
Other
292 stars 125 forks source link

JUnit5 DynamicContainer are not working #1617

Closed mapio closed 11 months ago

mapio commented 11 months ago

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.

jdneo commented 11 months ago

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.

jdneo commented 11 months ago

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.

mapio commented 11 months ago

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.

jdneo commented 11 months ago

What did you see from your side?

image

mapio commented 11 months ago

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.

mapio commented 11 months ago

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?

jdneo commented 11 months ago

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: https://github.com/microsoft/vscode-java-test/issues/1588

mapio commented 11 months ago

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!