我做了一些自动化测试,遇到了一个无法编译java.file的问题,我的源文件夹是项目的文件夹“test”。在这个文件夹中,我有2个jar文件:
hamcrest-core-1.3.jar文件
和
junit-4.13.jar
我运行以下命令:
javac -cp junit-4.13.jar;. src\r.java
我得到了下一个信息:
src\r.java:1: error: package org.junit.jupiter.api does not exist
import static org.junit.jupiter.api.Assertions.fail;
^
src\r.java:1: error: static import only from classes and interfaces
import static org.junit.jupiter.api.Assertions.fail;
^
src\r.java:2: error: package org.junit.jupiter.api does not exist
import static org.junit.jupiter.api.Assumptions.assumeTrue;
^
src\r.java:2: error: static import only from classes and interfaces
import static org.junit.jupiter.api.Assumptions.assumeTrue;
^
src\r.java:4: error: package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.AfterAll;
^
src\r.java:5: error: package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.AfterEach;
^
src\r.java:6: error: package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.BeforeAll;
^
src\r.java:7: error: package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.BeforeEach;
^
src\r.java:8: error: package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.Disabled;
^
src\r.java:9: error: package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.Test;
^
src\r.java:13: error: cannot find symbol
@BeforeAll
^
symbol: class BeforeAll
location: class r
src\r.java:17: error: cannot find symbol
@BeforeEach
^
symbol: class BeforeEach
location: class r
src\r.java:21: error: cannot find symbol
@Test
^
symbol: class Test
location: class r
src\r.java:25: error: cannot find symbol
@Test
^
symbol: class Test
location: class r
src\r.java:30: error: cannot find symbol
@Test
^
symbol: class Test
location: class r
src\r.java:31: error: cannot find symbol
@Disabled("for demonstration purposes")
^
symbol: class Disabled
location: class r
src\r.java:36: error: cannot find symbol
@Test
^
symbol: class Test
location: class r
src\r.java:42: error: cannot find symbol
@AfterEach
^
symbol: class AfterEach
location: class r
src\r.java:46: error: cannot find symbol
@AfterAll
^
symbol: class AfterAll
location: class r
src\r.java:27: error: cannot find symbol
fail("a failing test");
^
symbol: method fail(String)
location: class r
src\r.java:38: error: cannot find symbol
assumeTrue("abc".contains("Z"));
^
symbol: method assumeTrue(boolean)
location: class r
src\r.java:39: error: cannot find symbol
fail("test should have been aborted");
^
symbol: method fail(String)
location: class r
22 errors
我的代码是来自https://junit.org/junit5/docs/current/user-guide/
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
class r {
@BeforeAll
static void initAll() {
}
@BeforeEach
void init() {
}
@Test
void succeedingTest() {
}
@Test
void failingTest() {
fail("a failing test");
}
@Test
@Disabled("for demonstration purposes")
void skippedTest() {
// not executed
}
@Test
void abortedTest() {
assumeTrue("abc".contains("Z"));
fail("test should have been aborted");
}
@AfterEach
void tearDown() {
}
@AfterAll
static void tearDownAll() {
}
}
我做错了什么?求求你,救命!
1条答案
按热度按时间lnvxswe21#
这个
org.junit.juniper
包表明您的代码使用JUnit5。但是你的类路径上只有JUnit4。
要么遵循JUnit4用户指南,要么更改类路径以包含JUnit5。