Visual Studio代码中的Java测试运行器

问题描述 投票:2回答:1

我最近开始使用Visual Studio Code进行Java开发。我在测试跑步者方面遇到一些问题。

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

Screenshot 1Screenshot 2

这是学生类的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

有人知道如何获取测试文件以在文件中显示“运行测试”选项,或者如何在侧边栏中找到它吗?

java testing junit visual-studio-code
1个回答
0
投票

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

例如

<build>
        <testSourceDirectory>${basedir}/src/test/</testSourceDirectory>
</build>
© www.soinside.com 2019 - 2024. All rights reserved.