VSCode找不到单元测试

时间:2019-05-21 18:41:29

标签: java junit visual-studio-code vscode-settings

由于某种原因,我的VSCode在我的“测试资源管理器”中找不到我的单元测试。它能够找到该类,但不能找到该类中的任何方法。我认为我在vscode设置中必须配置有误,但不确定是什么。

下面是我要运行的课程的存根。

/**
 * 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 );
    }
    }

3 个答案:

答案 0 :(得分:0)

1。确保已安装J ava Test Runner 扩展

2。打开.classpath文件并更改

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

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

有关Unit Test

的更多信息

答案 1 :(得分:0)

您可以使用JUnit 4的注释:

AppTest.java

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

SuiteClass.java

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

}

答案 2 :(得分:0)

我刚刚遇到了同样的问题。我所有的测试类都没有用“运行测试”和“调试测试”进行注释。 我通过以下方式解决了 vs 代码中的问题:

在 vs 代码中的我的 Java 项目概述中(在具有打开的编辑器等的资源管理器部分)单击“更多操作”按钮(三个点)。

enter image description here

点击:“清理工作区”

接受提示:

enter image description here

相关问题