JUnit运行测试命令行 [英] JUnit run tests command line

查看:790
本文介绍了JUnit运行测试命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下结构

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

(Tester属于程序包测试)

(Tester belongs to package tests)

我可以使用

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

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

我得到以下输出:

JUnit version 4.10
Could not find class: tests.Tester

Time: 0.001

OK (0 tests)

如何解决此Could not find class问题?我认为可能与类路径有关.

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

推荐答案

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

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:

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

这篇关于JUnit运行测试命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆