英文:
Can't compile java file using CLI
问题
我做了一些自动化测试,遇到了一个问题,无法编译java文件。
我的源文件夹是项目的文件夹 "Test"。
在这个文件夹里我有两个jar文件:
<b>hamcrest-core-1.3.jar</b>
和
<b>junit-4.13.jar</b>
我运行了这个命令:
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() {
}
}
我做错了什么?
请帮忙解决!
英文:
I make some automated tests and faced with an issue that I can't compile the java.file
My source folder is the project's folder "Test".
In this folder i have 2 jar files:
<b>hamcrest-core-1.3.jar</b>
and
<b>junit-4.13.jar</b>
I run this command:
javac -cp junit-4.13.jar;. src\r.java
And I got the next message:
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
My code is the template from 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() {
}
}
What I do wrong?
Please, help!
答案1
得分: 1
org.junit.juniper
包表示您的代码使用了 JUnit 5。
但是您的类路径中只有 JUnit 4。
要么按照 JUnit 4 用户指南 进行操作,要么更改您的类路径以包含 JUnit 5。
英文:
The org.junit.juniper
packages indicates that your code uses JUnit 5.
But you've only got JUnit 4 on your classpath.
Either follow the JUnit 4 user guide or change your classpath to include JUnit 5.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论