junit4.jar and test file in same folder, can't find class

junit4.jar and test file in same folder, can't find class



I have junit4.jar in a folder along with TestMain.java



I successfully compiled test main, then I attempt to run it from command line with


java -cp junit4.jar org.junit.runner.JUnitCore TestMain



I get this error message


JUnit version 4.10
Could not find class: TestMain



But they're in the same folder! What am I missing here?






it might belong into the libs directory and the class into the test directory.

– Martin Zeitler
Sep 6 '18 at 1:07


libs


test






I don't have a project with directories. I have TestMain and junit.jar in one folder together. I need to run junit on TestMain which in turn runs a class loader and loads some other classes in that folder.

– ThisClark
Sep 6 '18 at 4:30




1 Answer
1



I think you need to add the current directory to the classpath.



Try (I added :. after junit-4.10.jar)



java -cp junit-4.10.jar:. org.junit.runner.JUnitCore TestMain


java -cp junit-4.10.jar:. org.junit.runner.JUnitCore TestMain



Please note that the JUnit version in your error message is different from the -cp jar version. I used version 4.10 because this is the one your error message shows.


-cp



Source: this Stack Overflow answer






I tried that and it did not work. I get new error, Error: Could not find or load main class org.junit.runner.JUnitCore In my question, I was loading junit just fine. The test runner just can't find the TestMain class also in the same folder.

– ThisClark
Sep 4 '18 at 3:11



Error: Could not find or load main class org.junit.runner.JUnitCore






@ThisClark what operating system do you use? stackoverflow.com/questions/4528438/…

– piradian
Sep 4 '18 at 5:09







Windows Linux or OSX

– ThisClark
Sep 4 '18 at 11:26






@ThisClark your original error message says your JUnit version is 4.10. Therefore your jar should be junit-4.10.jar. I updated the answer.

– Daniel Muñoz
Sep 6 '18 at 0:21






I renamed the jar. That’s irrelevant, but for what it's worth I put the name back to junit-4.10.jar and still no difference. In fact the :. at the end makes it completely not work. The problem is finding TestMain not running Junit. To be clear, JUnit is working okay, but it just doesn't see the class in the same folder with that name, TestMain.

– ThisClark
Sep 6 '18 at 4:24



:.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)