【问题标题】:Java Test Runner in Visual Studio CodeVisual Studio Code 中的 Java 测试运行程序
【发布时间】:2019-01-10 11:28:31
【问题描述】:

我最近开始使用 Visual Studio Code 进行 java 开发。我在测试运行器方面遇到了一些问题。

我可以在 .java 文件中运行 main() 没有任何问题,但是“运行测试”选项没有出现在我的 JUnit 测试文件中。此外,Test runner 侧栏中不会显示任何文件。

Screenshot 1 Screenshot 2

这是一个 Student 类的 JUnit 测试文件。

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Ignore;

class Student_test {
    @Test 
    public void testGetName() {
        Student john = "John Deer"; 
        String expected = "John Deer";
        String result = john.getName();
        assertEquals(result, expected); 
    }
 }

我在 VS Code 中使用 Java Test Runner 扩展: https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test

有谁知道我如何让测试文件在文件中显示“运行测试”选项,或者我如何在侧栏中找到它?

【问题讨论】:

  • 为什么不用IDEA或者eclipse,写java代码的时候比较流行。
  • 比起eclipse、intellij 和类似的Java IDE,我更喜欢VSC。如果我能让这个测试运行器正常工作,我就拥有了我目前开发时需要的所有功能。

标签: java testing junit visual-studio-code


【解决方案1】:

我相信您放置测试的文件夹是错误的。用于识别文件夹。 尝试在maven中设置测试目录

例如

<build>
        <testSourceDirectory>${basedir}/src/test/</testSourceDirectory>
</build>

【讨论】:

    猜你喜欢
    • 2020-12-27
    • 2019-10-21
    • 2017-06-16
    • 2022-07-11
    • 2014-03-14
    • 2017-04-12
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    相关资源
    最近更新 更多