0

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

4
  • 1
    If you have a module-info.java file, delete it. Otherwise, show what you have in Project > Properties: Java Build Path, in the Libraries tab. Commented Apr 7, 2020 at 11:06
  • howlger, I did have that file. Deleting it was sufficient. Can you explain why this caused all this trouble? Commented Apr 7, 2020 at 11:17
  • 1
    Having module-info.java means using JPMS which requires a requires ...; line in that file and the JAR on the modulepath, not on the classpath (-cp). Commented Apr 7, 2020 at 12:01
  • Same issue: stackoverflow.com/a/60447530/6505250 Commented Apr 7, 2020 at 13:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.