vscode-java-test icon indicating copy to clipboard operation
vscode-java-test copied to clipboard

When I run the spring source code test class, I get an error: No tests fount with test runner 'JUnit 5'

Open chang6666 opened this issue 1 year ago • 8 comments

as title,When I run the spring source code test class, I get an error: No tests fount with test runner 'JUnit 5' CleanShot 2024-03-27 at 09 41 53@2x eg:spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java

chang6666 avatar Mar 27 '24 01:03 chang6666

Is your java file name the same as your test primary class name? e.g.

class AbstractPropertyAccessorTests {
...
}

jdneo avatar Mar 27 '24 02:03 jdneo

@jdneo yes it is the same,I run the same code in idea without any exception,The source code address is at https://github.com/spring-projects/spring-framework/blob/6.1.x/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java

chang6666 avatar Mar 27 '24 02:03 chang6666

wait, what's the version of the test runner extension you are using? We've deprecated the code lens shortcuts for years.

jdneo avatar Mar 27 '24 08:03 jdneo

@jdneo
CleanShot 2024-03-27 at 17 05 52@2x

chang6666 avatar Mar 27 '24 09:03 chang6666

Where do those Run Test | Debug Test come from? I don't understand. We are using gutter icon now. Do you install other java extension?

jdneo avatar Mar 27 '24 12:03 jdneo

@jdneo Now that I have removed other test plug-ins, I still get an error CleanShot 2024-03-28 at 11 31 51@2x

chang6666 avatar Mar 28 '24 03:03 chang6666

Thank you. I need to make some investigation. Highly likely that we could not handle abstract test class.

To reproduce, simply use:

public abstract class AbstractTest {

    @Test
    void testName() {

    }
}

jdneo avatar Mar 28 '24 04:03 jdneo

Is the extension able to handle test cases in an abstract class? We recently shifted from Eclipse to VSCode. The following example test file matches your example above:

public abstract class QueueTest {

    /**
     * Invokes the appropriate {@code Queue} constructor for the implementation
     * under test and returns the result.
     *
     * @return the new queue
     * @ensures constructorTest = <>
     */
    protected abstract Queue<String> constructorTest();

    /**
     * Invokes the appropriate {@code Queue} constructor for the reference
     * implementation and returns the result.
     *
     * @return the new queue
     * @ensures constructorRef = <>
     */
    protected abstract Queue<String> constructorRef();

    @Test
    public final void testNoArgumentConstructor() {
        /*
         * Set up variables and call method under test
         */
        Queue<String> q = this.constructorTest();
        Queue<String> qExpected = this.constructorRef();
        /*
         * Assert that values of variables match expectations
         */
        assertEquals(qExpected, q);
    } 
}

The tests correctly have run buttons next to the line numbers, but clicking them raises an error (i.e., no tests found with testrunner JUnit 4). The class that inherits these tests can be executed just fine. I've been trying to figure out a workaround because my students often click these run buttons and wonder what's wrong.

For the record, switching to JUnit 5 actually makes the issue worse. Test failures no longer show alongside the correct test case and instead all of them show up on the class declaration line.

I can open another issue if this is not the appropriate location.

jrg94 avatar Sep 10 '24 18:09 jrg94

Hi @chang6666, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

Your test class (AbstractPropertyAccessorTests) is declared abstract, so VS Code’s JUnit 5 runner will not execute it directly. Only concrete classes can be launched.

Suggestions:

• Run a concrete subclass instead (for example, BeanWrapperPropertyAccessorTests or DirectFieldPropertyAccessorTests).

• If you really need to execute code from the abstract class, refactor it into a non-abstract helper and test that helper in a concrete test class.

• Confirm you have the JUnit 5 engine on the test classpath (for Maven projects, ensure you haven’t set java.import.maven.disableTestClasspathFlag: true).

Other references with low confidence:

See also
  • Title: The test runner does not find tests from the super class
    Description: VS Code runner skips tests in abstract classes (TestNG example). Likely related behavior for JUnit.
    URL: https://github.com/microsoft/vscode-java-test/issues/1492

  • Title: Test Runner for Java doesn’t recognize tests
    Description: Maven projects with disableTestClasspathFlag skip test folders, so no tests are discovered.
    URL: https://github.com/microsoft/vscode-java-test/issues/1782

The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

github-actions[bot] avatar Nov 12 '25 20:11 github-actions[bot]