您好我开始学习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
添加到Path。 和系统变量
JUNIT_HOME | C:\JUNIT\
答案 0 :(得分:2)
看起来你在运行命令中缺少类路径。
在Windows中
将环境变量CLASSPATH设置为
%CLASSPATH%;%JUNIT_HOME%\junit4.12.jar;.;
Linux的
export CLASSPATH = $CLASSPATH:$JUNIT_HOME/junit4.12.jar:.
的Mac
export CLASSPATH = $CLASSPATH:$JUNIT_HOME/junit4.12.jar:.