在终端中运行JUnit测试 [英] Running JUnit tests in terminal
问题描述
我是从终端运行Java的新手,目前正在尝试在终端中运行JUnit测试类.我的Java类的基本结构是
I'm new to running java from the terminal and am currently trying to run a JUnit test class in terminal. The basic structure of my java classes is
JavaProject
Queue.java
QueueTests.java
junit.jar
RunTests
RunTests是一个包含以下代码的脚本.
RunTests is a script with the following code.
#!/bin/sh
javac Queue.java
CLASSPATH=".:junit.jar:"; export CLASSPATH
javac QueueTests.java
java org.junit.runner.JUnitCore QueueTests
但是,当我运行此命令时,我总是从最后一行收到线程主"中的异常" java.lang.NoClassDefFoundError"错误.如果我注释掉最后一行,则没有错误.因此,似乎无法找到QueueTests.class.但是,查看该文件夹后,很明显,在我运行脚本后,Queue.class和QueueTests.class都存在.我不确定自己在做什么错.任何帮助将不胜感激.
However, when I run this, I always get a "Exception in thread "main" java.lang.NoClassDefFoundError" error from the final line. If i comment out the final line, there are no errors. As such, it seems like it is unable to find QueueTests.class. However, looking at the folder, it is clear after I run the script that both Queue.class and QueueTests.class are there. I am not sure what I am doing wrong. Any help would really be appreciated.
推荐答案
如果您尝试在Java中学习和试验类似的新事物,而不必加载完整/繁重的IDE,同时又不必运行冗长的终端命令我建议您使用轻量级的Java IDE,例如 Java博士.
If you are trying to learn and experiment new things like this in java without having to load up a full/heavy IDE and meanwhile without having to run lengthy terminal commands I would recommend you to use a lightweight java IDE like Dr Java.
PS:我假设您是从终端运行的,只是为了避免让IDE麻烦地更快地执行和运行此类较小的任务.
PS: I am assuming that you are running from terminal just to avoid the hassle of IDE to execute and run smaller tasks like this faster.
这篇关于在终端中运行JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!