英文:
java junit test fails to compile in eclipse
问题
在我的首次尝试中,我尝试同时使用junit和eclipse。我创建了一个小的测试类,它位于src目录中,以及一个小的测试对象,它位于单独的test目录中。src和test都被标记为源目录。
类本身的代码是正常工作的,我可以从eclipse中运行它,但是测试对象无法从eclipse中运行。Eclipse一直报错说:“类型org.junit.Assert不可访问”,出现在第一行“import static org.junit.Assert.*;”。我不知道该怎么办。
我已经将junit4添加到了类路径(构建路径>添加库> Junit> Junit4)。测试类是由eclipse自动生成的(新建Junit测试用例,junit4)。从命令行中,我可以将java文件编译成类文件,但是eclipse无法找到junit。
手动工作正常:
javac -cp /path/to/org.junit_4.13.0.v20200204-1500.jar Addtester.java
我肯定是错过了重要的细节,但是现在我已经没有了想法。
提前感谢,Ruud
英文:
For my first attempt to work with both junit and eclipse, I have created a small test class, which resides in the src directory and a small tester object. This resides in a seperate test directory. Both src and test are marked as source directory.
The code of the class itself is working. and I can run it from eclipse, but the test object fails to run from eclipse. Eclipse keeps saying "The type org.junit.Assert is not accessible" on the very first line "import static org.junit.Assert.*;". I cannot find out what to do.
I have put junit4 on the classpath (build path> add library> Junit> Junit4). The test class is created by eclipse itself (new Junit testcase, junit4). From the command line I can compile the java file to a class file, but eclipse refuses to find junit.
Manual works OK:
javac -cp /path/to/org.junit_4.13.0.v20200204-1500.jar Addtester.java
I must have overseen an important detail, but right now I am out of ideas.
Thanks in advance, Ruud
专注分享java语言的经验与见解,让所有开发者获益!
评论