mornindew
mornindew

Reputation: 2221

VSCode not finding unit tests

For some reason my VSCode is not finding my unit tests in my "Test Explorer". It is able to find the class but not any of the methods in the class. I think that I must have something misconfigured in my vscode setup but not sure what.

Below is my stub of a class that I am trying to run.

/**
 * Unit test for simple App.
 */
public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
    }

Upvotes: 11

Views: 36122

Answers (4)

Mario.Cadiz
Mario.Cadiz

Reputation: 346

I had the same issue, somehow I created the test class under the normal java folder (main/java), and not under the test folder(main/test). Moving this test class under test folder fixed the issue. enter image description here

Upvotes: 2

FishingIsLife
FishingIsLife

Reputation: 2372

I just had the same problem. All my test classes were not annotated with "Run Test" and "Debug test". I fixed the problem in vs code the following way:

In my Java Projects overview within the vs code ( In the Explorer section with open editors etc.) click on the "more actions" button ( the three dots ).

enter image description here

Click : "Clean workspace"

Accept the prompt:

enter image description here

Upvotes: 17

ShengChen
ShengChen

Reputation: 11

You can use JUnit 4's annotation:

AppTest.java

public class AppTest {
    @Test
    public void testApp() {
        assertTrue( true );
    }
}

SuiteClass.java

@RunWith(Suite.class)
@SuiteClasses({AppTest.class})
public class SuiteClass {

}

Upvotes: 1

Leo Zhu
Leo Zhu

Reputation: 15031

1.make sure you have installed Java Test Runner extension

2.open the .classpath file and change

<classpathentry kind="src" path="src/test/java" />

to

<classpathentry kind="src" path="src/test/java" output="build/classes/test">
   <attributes>
      <attribute name="test" value="true" />
   </attributes>
</classpathentry>

more infomation about Unit Test

Upvotes: 10

Related Questions