- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用命令提示符和以下命令编译我的 java 文件“check4PrimeTest.java”:
javac -classpath .:junit.jar check4PrimeTest.java
我收到以下错误:
error: package junit.framework does not exist import junit.framework.*;
我不确定为什么会出现此错误,因为我在我的程序中导入了 junit.framework.*。
下面是我的代码:
package check4prime;
// check4PrimeTest.java
//Imports
import junit.framework.*;
public class check4PrimeTest extends TestCase {
//Initialize a class to work with.
private check4Prime check4prime = new check4Prime();
//constructor
public check4PrimeTest (String name) {
super(name);
}
//Main entry point
public static void main(String[] args) {
System.out.println("Starting test...");
junit.textui.TestRunner.run(suite());
System.out.println("Test finished...");
} // end main()
//Test case 1
public void testCheckPrime_true() {
assertTrue(check4prime.primeCheck(3));
}
//Test cases 2,3
public void testCheckPrime_false() {
assertFalse(check4prime.primeCheck(0));
assertFalse(check4prime.primeCheck(1000));
}
//Test case 7
public void testCheck4Prime_checkArgs_char_input() {
try {
String [] args= new String[1];
args[0]="r";
check4prime.checkArgs(args);
fail("Should raise an Exception.");
} catch (Exception success) {
//successful test
}
} //end testCheck4Prime_checkArgs_char_input()
//Test case 5
public void testCheck4Prime_checkArgs_above_upper_bound() {
try {
String [] args= new String[1];
args[0]="10001";
check4prime.checkArgs(args);
fail("Should raise an Exception.");
} catch (Exception success) {
//successful test
}
} // end testCheck4Prime_checkArgs_upper_bound()
//Test case 4
public void testCheck4Prime_checkArgs_neg_input() {
try {
String [] args= new String[1];
args[0]="-1";
check4prime.checkArgs(args);
fail("Should raise an Exception.");
} catch (Exception success) {
//successful test
}
} // end testCheck4Prime_checkArgs_neg_input()
//Test case 6
public void testCheck4Prime_checkArgs_2_inputs() {
try {
String [] args= new String[2];
args[0]="5";
args[1]="99";
check4prime.checkArgs(args);
fail("Should raise an Exception.");
} catch (Exception success) {
//successful test
}
} // end testCheck4Prime_checkArgs_2_inputs
//Test case 8
public void testCheck4Prime_checkArgs_0_inputs() {
try {
String [] args= new String[0];
check4prime.checkArgs(args);
fail("Should raise an Exception.");
} catch (Exception success) {
//successful test
}
} // end testCheck4Prime_checkArgs_0_inputs
//JUnit required method.
public static Test suite() {
TestSuite suite = new TestSuite(check4PrimeTest.class);
return suite;
} //end suite()
} //end check4PrimeTest
最佳答案
您收到此错误是因为您试图在不告知系统包所在位置的情况下导入包。以下是告诉您的系统包裹所在位置的说明:
Your javac target doesn't specify anything apart from the source and target directory - it doesn't add any classpath entries; you'll need to add an entry for the appropriate JUnit jar file. See the javac task documentation for more details. You may want to specify the path to JUnit as a classpath attribute, a nested element, or a reference to a path declared elsewhere.
来源:problem running JUnit tests with Ant in Eclipse. Beginner question
提示> javac -classpath .;$JUNIT_HOME\junit4.x.x.jar test.java
编辑:JUNIT 安装(来自 here):
Windows
To install JUnit on Windows, follow these steps:
1. Unzip the junit.zip distribution file to a directory referred to as %JUNIT_HOME%.
2. Add JUnit to the classpath (type the following into a command line shell): `set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%\junit.jar`Unix (bash)
To install JUnit on Unix, follow these steps:
1. Unzip the junit.zip distribution file to a directory referred to as $JUNIT_HOME.
2. Add JUnit to the classpath (type the following into terminal):
`export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit.jar`
关于javac 错误 : "package x does not exist" at "import x",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12718723/
我的问题是关于基本的java命令之一“javac”。我的桌面上有一个“.java”文件。我已经安装了 JDK 7 并将路径变量添加到环境变量中。这是“环境变量”的屏幕截图。 http://s13.po
我制作了我的 gitrepository 并提交了它。 插入了一个 java 文件并想编译它,但它给了我这个: Bernard@BERNARD-PC /c/users/bernard/desktop/
运行Maven时,得到以下输出: [WARNING] Unable to autodetect 'javac' path, using 'javac' from the environment. 我该
我有一个导入一些 servlet 库的类。当我从命令行编译它时它很好。 当我使用 ant compile 任务编译它时,它给出了在其路径中找不到 servlet 库的错误。 这是已知/常见的情况吗?
我试图在 maven-compiler-plugin 中指定另一个版本的 JDK .当-target和 -source参数设置为1.5,一切正常。但是当我尝试使用 1.6 JDK 时,maven 会报
我们的软件之前附带 OpenJDK JRE,但现在我们将附带 Oracle JRE。 之前我们使用 OpenJDK javac 编译器进行编译。我认为现在我们应该使用 Oracle javac 编译器
在大多数现代 IDE 中,您可以设置一个参数来确保 javac 获得足够的堆内存来进行编译。由于不值得在这里讨论的原因,我们暂时与 JBuilder 2005/2006 联系在一起,而且源代码的数量似
我在桌面上的 Notepad++ 中保存了一个名为“first.java”的文件。当我运行 cmd 命令“javac first.java”时,它给了我这个错误。 javac: file not fo
更新: See resolution here. 感谢大家的帮助! 我在尝试使用 Ant 编译项目时遇到错误,它声称“[javac] javac:无效目标版本:7”并导致构建失败。 我在 Mac OS
当我尝试在我的 gwt-maven Projekt 上进行 maven-install 时,我得到了这个错误: [ERROR] Failed to execute goal org.apache.ma
使用 maven 编译时出现编译错误。 [ERROR] COMPILATION ERROR : [INFO] ---------------------------------------------
我正在查看一些内部 javac sun 编译器 API 源代码,并在 Types 类中发现了这一点: public Boolean visitTypeVar(TypeVar var1, Type va
我正在尝试运行 java 应用程序,但出现以下错误, Unable to find a javac compiler; com.sun.tools.javac.Main is not on the c
我有这个类,它是我在从 Java 6 移植到 Java 8 的项目中找到的一些代码的简化: public class Unification { final class Box {}
首先,我要感谢你,并明确地说,我已经在这个问题上苦苦思索了好几天,并在其他类似线程中寻找解决方案,但没有成功。 我们的应用程序负责生成 java 类,其中一些可能在类名(因此文件名)中包含特殊字符,例
以下代码创建了一个Collector,它产生了一个UnmodifiableSortedSet: package com.stackoverflow; import java.util.Collecti
当我用 Maven 编译我的类时遇到问题。堆栈跟踪如下所示: [ERROR] Failure executing javac, but could not parse the error: [ERRO
这个问题在这里已经有了答案: Why Java compiler as distributed as executable and not as JVM bytecode? (1 个回答) 关闭 7
我有一些用 javac 1.8.0_92 编译的代码: public final class Either { // ... private final L l; privat
这个问题在这里已经有了答案: Lombok's access to jdk.compiler's internal packages incompatible with Java-16 (3 个回答)
我是一名优秀的程序员,十分优秀!