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
293 stars 125 forks source link

Run tests on class does not take inherited methods into consideration #435

Open maxandersen opened 5 years ago

maxandersen commented 5 years ago

When you have a test class with inherited test methods only the methods explicitly marked on the current class gets run. Would have expected it to run all tests.

Example: https://github.com/jbake-org/jbake/blob/master/jbake-core/src/test/java/org/jbake/app/template/FreemarkerTemplateEngineRenderingTest.java#L40

If you run this only 2 tests are run, none of the @Test from its super class (https://github.com/jbake-org/jbake/blob/master/jbake-core/src/test/java/org/jbake/app/template/AbstractTemplateEngineRenderingTest.java) are run

joshmanderson commented 5 years ago

I might also add that along with tests inherited from a parent class, it would be useful to also be able to run tests from default interface methods. Note: I'm pretty sure this requires running the tests using junit 5+ (if using junit).

E.g. Given:

public interface CanJumpTest<TestInstance extends CanJump> {
    TestInstance getTestInstance();

    int getMinExpectedJumpHeight();

    @Test
    default void canJumpToExpectedHeight()  {
        assertThat(getTestInstance().jump()).isGreaterThanOrEqualTo(getMinExpectedJumpHeight());
    }
}
public class BasketballPlayerTest implements CanJumpTest<BasketballPlayer> {
    @Override
    BasketballPlayer getTestInstance() {
        return new BasketballPlayer();
    }

    @Override
    int getMinExpectedJumpHeight() {
        return 70;
    }
}

Running BasketballPlayerTest should run the canJumpToExpectedHeight test.

jdneo commented 5 years ago

This issue will be addressed in 0.15.0

We refactored the logic of parsing the test results recently.

lanfuchao commented 5 years ago

Is this issue fixed? encounter the same issue in 0.19.0.

Sunnyxpected commented 4 years ago

is there an update to this? I'm currently working around it by just dragging the inherited methods into the classes, which is quite messy

jdneo commented 4 years ago

@Sunnyxpected We have limited support for this scenario, but if you trigger the tests at the inherited class, the methods from the super class should also get run and appear in the test report. Could you provide more information about the problem you have?

Sunnyxpected commented 4 years ago

i have lets say a LoginAbstract class, which contains the Test Method. then i have a class called LoginFooTest which inherits said abstract class, but overrides an abstract method called getUser. if i then run the tester on the class, my expected result (from past working with eclipse) is that the test runner runs the inherited methods, however he doesnt

My current workaround is to just copy in all the test methods from the parent

jdneo commented 4 years ago

@Sunnyxpected Seems some words are missing in the comments.

Do you mean you want to run the methods in the super type and hope to get the results for all the inherited ones?

Sunnyxpected commented 4 years ago

yes there is test methods in the super type that i want to run in the subtype which inherits those.

mic4126 commented 3 years ago

As I see this issue do not updated for a long time.

I created a minimal repo to reproduce the bug. Hope it can help to solve this issue.

https://github.com/mic4126/vscode_java_test_abstract_class_bug

cmitchell commented 2 years ago

Any movement or update on this? This is a pretty common scenario for decently sized java projects.

benzman81 commented 2 years ago

Seems to be duplicate or releated to #718.

This makes it almost impossible to switch from eclipse to vscode. We are not able to execute most of our testclasses because of this bug.

jdneo commented 2 years ago

@cmitchell Are you using TestNG?

vadiml77 commented 2 years ago

We're using VsCode's Test Runner for Java plugin v0.35.2022070202 plugin, and are seeing the same issue. A test case that is located in a parent class and annotated with "@Test", does not show up in the test case sequence as the first test.

The same setup in Eclipse does work correctly.

@microsoft - are you planning to address this issue?

jdneo commented 2 years ago

@vadiml77 do you mean the case from parent class appears in the test explorer but not at the first place?

vadiml77 commented 2 years ago

@jdneo I mean that the test case from the parent class does NOT appear in the test explorer at all. For example as setup below, the vscode explorer shows TEST01() as the first test, and does not show/execute TEST() at all. However, in the Eclipse, the explorer does show/execute TEST() as the very first test.

public class ChildClass extends ParentClass { @Test(enabled = true, priority = 1) public void TEST01() { ... } ... }

public class ParentClass { @Test(enabled = true) public void TEST() { ... } }

jdneo commented 2 years ago

I guess you are using TestNG, which currently does not support well for inherited tests. JUnit should be fine though.

vadiml77 commented 2 years ago

@jdneo yes, we're using TestNG. Is there a roadmap for having inherited tests supported in VSCode to match the level of support Eclipse provides? This is a requirement for large sized software

cmitchell commented 2 years ago

@jdneo No, we are using both junit 4 and 5 at the moment, but hopefully soon only junit 5 (jupiter). Zero testNG

benzman81 commented 2 years ago

I guess you are using TestNG, which currently does not support well for inherited tests. JUnit should be fine though.

@jdneo testng works very well for inherited classes and eclipse supports this, too. This is a major lack in vscode support for testng.

@vadiml77 I feel your pain, we have the same issue and habe to switch to maven command line test runs for this.