我最近开始使用Visual Studio Code进行Java开发。我在测试跑步者方面遇到一些问题。
我可以在.java文件中运行main(),没有任何问题,但是“ run test”选项没有显示在我的JUnit测试文件中。此外,“测试运行器”侧栏中没有文件显示。
这是学生类的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
有人知道如何获取测试文件以在文件中显示“运行测试”选项,或者如何在侧边栏中找到它吗?
我相信您要放置测试的文件夹是错误的。对于要识别的文件夹。尝试在Maven中设置测试目录
例如
<build>
<testSourceDirectory>${basedir}/src/test/</testSourceDirectory>
</build>