How can I access the test class from the main Maven folder?
I created a Maven project with a standard folder structure - i.e. src / main / java, src / test / java, etc.
I wrote class ClassA and test class TestA.
From the main ClassA program, I refer to the static member TestA.
The code compiles, but when I run it I get: NoClassDefFoundError: TestA.
How can I access TestA from ClassA?
source to share
Rather than addressing your problem directly, I would suggest rethinking your test project. Maven is great at running tests on its own, just type
mvn test
at the command line. If you want to run one test class, enter
mvn test -Dtest=MyTest
for one test method use
mvn test -Dtest=MyTest#shouldRunPerfectly
It also supports wildcards, so to run some common tests you can type
mvn test -Dtest=Integration*#shouldBeFaster*
...
Most IDEs allow you to run tests directly using a shortcut. If I remember correctly, > is for IntelliJ. IntelliJ also uses the + + shortcut to navigate to the test of the class you are working with. Shift X CtrlShiftT
Maven's directory structure emphasizes the separation of tests from the application and makes it a lot harder to do what you plan.
tl; dr - make it maven way
source to share