this appears to occur because only the source code is compiling when you use
mvn clean compile (i'm using maven 3.1.0 so i'm not sure if it always behaved like this).
if you run
mvn test, the test code will compile as well, but then it runs the tests (which may not be immediately desirable if you're trying to run them through eclipse.) the way around this is to add
test-compile to your maven command sequence whenever you do a
mvn clean. for example, you would run
mvn clean compile test-compile.
might be you forgotten to place the main class and test case class in /src/test/java. check it once.
check if your project is opened as a maven project and not just a regular java project. actually a no-brainer, but that is exactly the same reason why you might miss it.
i had faced the same issue. i solved it by removing the external junit jar dependency which i added by download from the internet externally. but then i went to project->properties->build path->add library->junit->choosed the version(ex junit4)->apply.
it automatically added the dependency. it solved my issue.
making some dummy change and saving the test class can solve the problem. it will build the .class automatically
these steps worked for me.
- delete the content of local maven repository.
- run mvn clean install in the command line. (cd to the pom directory).
- build project in eclipse.
1- mvn eclipse:eclipse
2- project clean all projects
it's worth mentioning as another answer that if you're using egit, and your classpath gets updated because of say, a test coverage tool like clover, that sometimes there's a cleanup hiccup that does not completely delete the contents of
essentially, i used eclipse's error log view, identified what was causing issues during this cleanup effort, navigated to the source directory, and manually deleted the
<project name>/bin directory. once that finished i went back to eclipse and refreshed (
f5) my project and the error went away.
it can also be due to "[error] no compiler is provided in this environment. perhaps you are running on a jre rather than a jdk?"
i had the same problem with a gradle project with a test sourceset with two resource directories.
this snippet comes from a main-module.gradle and adds a resource dir to the test sourceset:
doing this i had two resource directories related to the test sourceset of the project main-module:
../other-module/src/test/resources src/test/resources (relative to the main-module folder, automatically added by the java plugin)
i find out that if i had two files with the same name in both the source directories, something in the process resources stage went wrong. as result, no compilation started and for this reason no .class were copied in the bin directory, where junit was looking for the classes. the classnotfoundexception disappeared just renaming one of the two files.
it seems compile issue. run project as maven test, then run as junit test.
for project that does not use maven : this worked for me https://ihategeek.wordpress.com/2012/04/18/eclipse-junit-test-class-not-found/
adding the jre and project src at the bottom in order and exports in build path
pls check if you have added junit4 as dependency.
earlier, in this case, i always did mvn
eclipse:eclipse and restarted my eclipse and it worked. after migrating to git, it stopped working for me which is somewhat weird.
basic problem here is mr eclipse does not find the compiled class.
then, i set the output folder as project/target/test-classes which is by default generated by
mvn clean install without skipping the test and proceeded with following workaround:
option 1: set classpath for each test case
eclipse ->run ->run configurations ->under junit->select mytest -> under classpath tab->select user entries->advanced->add folder -> select ->apply->run
option 2: create classpath variable and include it in classpath for all the test cases
eclipse ->windows ->classpath variables ->new->[name : junit_test_cases_cp | path : ]->ok then go to eclipse->run ->run configurations ->junit->select mytest ->under classpath tab ->select user entries->advanced->add classpath variables->select junit_test_cases_cp->ok->apply->run
this is the only thing currently working for me after trying all the suggestions online.
i had the similar problem with my eclipse helios which debugging junits. my problem was little different as i was able to run junits successfully but when i was getting classnotfoundexception while debugging the same junits.
i have tried all sort of different solutions available in stackoverflow.com and forums elsewhere, but nothing seem to work. after banging my head with these issue for close to two days, finally i figured out the solution to it.
if none of the solutions seem to work, just delete the .metadata folder created in your workspace. this would create an additional overhead of importing the projects and all sorts of configuration you have done, but these will surely solve these issue.
hope these helps.
noclassdeffounderror really means it can't initilize the class. it has nothing to do with finding the class. i got this error when calling trim() on a null string.
junit won't show nullpointerexception. the string isn't null when running normally because i'm fetching the string from a properties file which is not availible for tests.
my advice is to remove pieces from the class until your tests start passing. then you can determine which line is giving the error.
in my case, changing the order of maven dependencies from build path configuration did not work for me. i changed its order from run configuration.
follow these steps:
• go to run -> run configurations...
• click on the unit test's run configuration and click on the classpath tab.
• check use temporary jar to specify classpath (to avoid classpath length limitations).
may be it is enough and your test works. you should try, so press run button. if it did not work. follow all previous steps again and without pressing run button, go to the next step.
• in sub branches of user entries move maven dependencies above your project or test class.
• click run button.
in my case, only next steps helped me to resolve this issue:
- project->properties->run/debug settings.
- in "launch configurations for '.....'" select classes/projects
- edit -> classpath -> "restore default entries"
in my case i had a wrong maven directory structure.
which should be like:
after i fixed that - everything worked like a charm.
i fixed my issue by running maven update. right click project your project > maven > update project
after having tried everything here with no improvement, i solved my issue by just restarting eclipse
if this problem occurs in eclipse only, executing command project -> clean... on selected project may help.
i faced the same problem and i was able to fix it using @slomek's answer but the issue resurfaced after that.
i finally fixed it by adding my project's output folder to the junit test's run configuration. steps are:
- find your project's output folder from
project properties -> java build path -> default output folder
- usually this is
- usually this is
- go to
run -> run configurations...
- click on the unit test's run configuration and click on the
- explicitly add your project's output folder under
user entries- even if the project is already included there
- click on
advanced -> add folderto add the output folder
- click on
this issue might be due to weird project setup in eclipse - e.g. source folder with nested maven projects imported as a single project/folder (at least that was how my project was setup).
i had a similar problem with my tests and found somewhere in the web, that you have to go to build path in your project's properties and move maven dependencies above jre system library. that seems to have worked for me.
- Class Not Found Exception when running JUnit test
- Getting class not found Exception when running in eclipse
- Getting Class Not found Exception when try to run test in eclipse
- Junit test not found system property when run from Eclipse
- Eclipse Class not found Exception even when jars are included in classpath
- Error: Unable to load configuration. - action, Caused by: Action class not found , when running Struts 2 on apache on eclipse
- JVMUtil class not found when attempting to use JOGL Swing test code
- AbstractMethodError found when running unit test in Eclipse not when running in Cygwin
- Running a Junit test from Eclipse throwing No class definition found error?
- JUnit test cases not displayed in JMtere when create a tests in simple class file but are displayed when create for JUnit class
- class not found exception while running my camera with face detection project
- Eclipselink throws exception when running JUnit test
- Existing JUnit Class not found exception
- Eclipse/Maven: JUnit tests not compiled when running them
- Tomcat & Spring Web - Class Not Found Exception org.springframework.web.context.ContextLoaderListener
- How to get Eclipse to jump to failed JUnit test when test is not a Java method
- maven + eclipse + tomcat : class not found exception
- Could not find class 'android.webkit.WebResourceResponse' when running HelloCordova on Android 2.2
- Maven surefire arguments when running JUnit test via eclipse
- Why I am getting class not found exception for Class.forName("com.mysql.jdbc.Driver");
- JUnit5 tests work fine with maven but not when run through Eclipse, "No tests found with test runner 'JUnit 5'."
- Class not found when using JAX-RS with Eclipse and Glassfish
- ClassNotFoundException when running a junit test in eclipse
- java.lang.NoClassDefFoundError when running JUnit plug-in test
- class not found exception Class.forName("com.mysql.jdbc.Driver") in webservice
- Prevent launching eclipse GUI when running JUnit Plug-in Test
- Static resources not found in (Selenium) JUnit test for Play 2.0 application executed from Eclipse
- Is there a way to use a custom JUnit Test Runner when running tests in Eclipse?
- resource not found exception Resource ID #0xffffffff when working in list view
- Java won't open the correct file, constantly returns the File Not Found Exception even when using the absolute path
More Query from same tag
- How do I attach the Android Support Library source in Eclipse?
- Unable to create Hbase table from windows eclipse
- Why Does Eclipse Restart When Workspaces are Switched?
- Why is there no association with ClearCase for my Eclipse project?
- Eclipse as an cross platform IDE for C++ code on Linux and Windows
- Building Eclipse from source
- Troubles with PyDev and external libraries in OS X
- in play framework, the file xx.java could not be compiled. error raised is : the import yyy cannot be resolved in eclipse
- How to debug Android system app with Maven in Eclipse
- VisualSVN Server and Eclipse new repository setup
- How to change the APK icon?
- Antlr4 Parse Tree view stays empty
- Debug a Python C++ extension from Eclipse (under Linux)
- How to navigate to implementing class from interface in Eclipse?
- sorting a list of pointers c++ - no matching function error
- Node.JS debugging with Eclipse and Chromium Dev Tools V8
- Eclipse Jar export script
- Step into Java EE code in Eclipse
- :checkDebugManifest FAILED => file specified for property 'manifest' does not exist
- Java script files are not showing in debug mode in broweser in odoo 9
- Why the Android emu crashes?
- How to invoke an Android Dalvik internal method using Java reflection?
- SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error
- Errors during GWT project export
- Eclipse is not creating default project and main layout in ADT
- Remove unused jar from eclipse project
- Publish filtered web.xml on eclipse tomcat
- Android Project not running on emulator.in Eclipse
- How to go to specific folder in Eclipse?
- Eclipse: show problem where the (keyboard) cursor is?