问题描述
我无法弄清楚如何将JUnit正确安装到我的Mac上。我知道我应该将其添加到路径环境变量中,我已经尝试了一些我在Google上发现的教程,如何做到这一点,但是我不断收到错误。
这是我使用的教程的链接:
,然后单击链接的junit.jar
。找到最新稳定版本的行,然后在下载列下单击jar链接。这将下载一个文件 junit-X.Y.jar
。重复此操作,并下载最新的稳定版本的hamcrest:下载 hamcrest-core-XX.YY.jar
cd&&&&&&& mkdir java
。然后运行 cp〜/ Downloads / {junit-X.Y.jar,hamcrest-core-XX.YY.jar}〜/ java /
复制两个.jars。 (替换 X
, Y
, XX
, YY
相应)。 [注意:如果文件夹位置变得不方便,不要担心,您可以随时更改jUnit文件夹]。 编辑您的类路径。我们现在需要编辑我们的 Edit your classpath. We now need to edit our .bash_profile
文件将这些文件添加到我们的类路径中(如果您使用zsh编辑您的 .zshrc
junit.jar
. Find the row for the latest stable release then under the downloads column click 'jar' link. This will download a file junit-X.Y.jar
. Repeat this again and download the latest stable release for hamcrest: download hamcrest-core-XX.YY.jar
java
folder in your home directory by running cd && mkdir java
. Then running cp ~/Downloads/{junit-X.Y.jar,hamcrest-core-XX.YY.jar} ~/java/
to copy the two .jars there. (replace X
, Y
, XX
, YY
accordingly). [Note: If the folder placement becomes an inconvenience, don't worry, you can change the jUnit folder at any later date]..bash_profile
file to add these files to our classpath (if you are using zsh edit your .zshrc
file).export JUNIT_HOME="$HOME/java"
export PATH="$PATH:$JUNIT_HOME"
export CLASSPATH="$CLASSPATH:$JUNIT_HOME/junit-X.Y.jar:$JUNIT_HOME/hamcrest-core-XX.YY.jar"
测试它的作品。重新启动你的终端运行 echo $ CLASSPATH
,应该没有错误,抱怨文件无法找到。现在用一个简单的测试用例创建一个测试文件。在 java
文件夹中,创建一个名为 TestBasic.java
的文件:
Test it works. Restart your terminal. Run echo $CLASSPATH
, there should be no errors that complain that files are unable to be found. Now create a test file with a trivial test case. In your java
folder, create a file called TestBasic.java
with:
import junit.framework.TestCase;
public class TestBasic extends TestCase {
public void testTrue() {
assertTrue(true);
}
}
现在cd进入 java
目录运行 javac TestBasic.java
后跟 java org.junit .runner.JUnitCore TestBasic
。如果一切正常,那么您将得到如下输出:
Now cd into the java
directory run javac TestBasic.java
followed by java org.junit.runner.JUnitCore TestBasic
. If everything is ok, then you will get an output like:
JUnit version 4.11
.
Time: 0.006
OK (1 test)
这篇关于需要帮助在Mac上安装JUnit /如何在Mac OSX上添加JUnit到Path环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!