我有一个JUnit项目,我想添加到一个工具链中。这个工具链使用Makefile。Makefile不在我的prject目录中。因此,我尝试在这个makefile中设置一个“测试”规则如下:
PROJPATH=TestJUnit/Test/
PACKAGE=com/project/package/name/
LIB=$(PROJPATH)lib/
SRC=$(PROJPATH)src/$(PACKAGE)
BIN=$(PROJPATH)bin/$(PACKAGE)
--------- All the acces to lib.jar and .class used during the test ------
CLASSPATH=.:$(LIB)junit.jar:$(LIB)opal-library.jar:$(SRC):$(BIN)
--------- Name of test in order of wanted excecution -------------
JAVASRC= Test1\
Test2\
Test3\
test:
java -classpath $(JUNITPATH) org.junit.runner.JUnitCore $(JAVASRC)
当我试着启动“做测试”
我收到以下信息:
JUnit version 4.11
Exception in thread "main" java.lang.NoClassDefFoundError: Test1 (wrong name: com/project/name/Test1)
我尝试了一切可能的方法,甚至在我的项目目录中启动java命令,但是没有任何效果。所有的.class和.java都分别在bin和src的董事会中。
发布于 2014-08-19 14:01:11
好的,伙计们,我喜欢这个问题。似乎类路径并不坏,但是调用测试的方式是错误的。只需在类路径中添加/src和/bin (没有子包目录),并将包名连接到测试类名,测试就会成功启动。
就像这样:
PROJPATH=TestJUnit/Test/
PACKAGE=com.project.package.name.
LIB=$(PROJPATH)lib/
SRC=$(PROJPATH)src/
BIN=$(PROJPATH)bin/
--------- All the acces to lib.jar and .class used during the test ------
CLASSPATH=.:$(LIB)junit.jar:$(LIB)opal-library.jar:$(SRC):$(BIN)
--------- Name of test in order of wanted excecution -------------
JAVASRC= $(PACKAGE)Test1\
$(PACKAGE)Test2\
$(PACKAGE)Test3\
test:
java -classpath $(JUNITPATH) org.junit.runner.JUnitCore $(JAVASRC)
https://stackoverflow.com/questions/25359641
复制相似问题