gpt4 book ai didi

java - JUnit 入门

转载 作者:行者123 更新时间:2023-11-28 21:08:04 26 4
gpt4 key购买 nike

嗨,我开始学习 junit,但我有以下问题

C:\JUNIT_WORKSPACE>javac TestJunit.java TestRunner.java
TestJunit.java:1: error: package org.junit does not exist
import org.junit.Test;
^
TestJunit.java:2: error: package org.junit does not exist
import static org.junit.Assert.assertEquals;
^
TestJunit.java:2: error: static import only from classes and interfaces
import static org.junit.Assert.assertEquals;
^
TestRunner.java:1: error: package org.junit.runner does not exist
import org.junit.runner.JUnitCore;
^
TestRunner.java:2: error: package org.junit.runner does not exist
import org.junit.runner.Result;
^
TestRunner.java:3: error: package org.junit.runner.notification does not
exist
import org.junit.runner.notification.Failure;
^
TestJunit.java:4: error: cannot find symbol
@Test
^
symbol: class Test
location: class TestJunit
TestJunit.java:7: error: cannot find symbol
assertEquals("Junit is working fine",str);
^
symbol: method assertEquals(String,String)
location: class TestJunit
TestRunner.java:6: error: cannot find symbol
Result result = JUnitCore.runClasses(TestJunit.class);
^
symbol: class Result
location: class TestRunner
TestRunner.java:6: error: cannot find symbol
Result result = JUnitCore.runClasses(TestJunit.class);
^
symbol: variable JUnitCore
location: class TestRunner
TestRunner.java:7: error: cannot find symbol
for (Failure failure : result.getFailures()) {
^
symbol: class Failure
location: class TestRunner
11 errors

学习来源:https://www.tutorialspoint.com/junit/junit_environment_setup.htm

我有路径:

%JUNIT_HOME%\junit-4.12

添加到路径。和系统变量

JUNIT_HOME | C:\JUNIT\

最佳答案

看起来您在运行命令中缺少类路径。

What is a classpath in java

在 Windows 中

设置环境变量CLASSPATH为

 %CLASSPATH%;%JUNIT_HOME%\junit4.12.jar;.;

Linux

export CLASSPATH = $CLASSPATH:$JUNIT_HOME/junit4.12.jar:.

苹果

export CLASSPATH = $CLASSPATH:$JUNIT_HOME/junit4.12.jar:.

关于java - JUnit 入门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49034002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com