java JUnit 运行测试命令行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13146557/
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-31 11:39:08  来源:igfitidea点击:

JUnit run tests command line

javajunit

提问by Alex

I've got the following structure

我有以下结构

lib/junit-4.10.jar
tests/Tester.java
tests/Tester.class
build/jar/jar_file.jar

(Tester belongs to package tests)

(Tester属于包测试)

I can compile tests using

我可以使用编译测试

javac -cp build/jar/jar_file.jar:lib/junit-4.10.jar tests/*.java

However I can't seem to run tests:

但是我似乎无法运行测试:

java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester

or

或者

java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore Tester

And I get the following output:

我得到以下输出:

JUnit version 4.10
Could not find class: tests.Tester

Time: 0.001

OK (0 tests)

How do I resolve this Could not find classproblem? I think it may be classpath related.

我该如何解决这个Could not find class问题?我认为这可能与类路径有关。

回答by Guido Simone

Assuming this is Linux/Mac (not Windows) and your path separator is correct (:), since your test class files exist in package subdirectories under the current working directory (.) You need to add "." to your class path, for example:

假设这是 Linux/Mac(不是 Windows)并且您的路径分隔符是正确的 (:),因为您的测试类文件存在于当前工作目录 (.) 下的包子目录中,您需要添加“.” 到您的课程路径,例如:

java -cp .:build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester

回答by RNJ

The classpath should be semi colon separated (on Windows - not sure what you are using.)

类路径应该用分号分隔(在 Windows 上 - 不确定你在使用什么。)

java -cp build/jar/jar_file.jar;lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester

Also with this command line you will need to run it in your project root

同样使用此命令行,您需要在项目根目录中运行它