java 如何从命令行在 JUnit 中运行测试用例?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5170621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:48:28 来源:igfitidea点击:
How to run test case in JUnit from command line ?
提问by Adham
I'm trying to run a JUnit test case from command line using this command:
我正在尝试使用以下命令从命令行运行 JUnit 测试用例:
F:\>java org.junit.runner.JUnitCore org.junit4.9b2.junit.SimpleTest
but I get this error:
但我收到此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore
Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.junit.runner.JUnitCore. Program will exit.
What is the problem?
问题是什么?
回答by Sean Patrick Floyd
Obviously you need junit on the classpath :-)
显然你需要在类路径上使用 junit :-)
java -cp path/to/junit.jar:path/to/local/classes org.junit.runner.JUnitCore \
org.junit4.9b2.junit.SimpleTest
(replace the :
with ;
on windows platforms)
(替换:
用;
在Windows平台上)