7

I use Eclipse IDE: Eclipse Java EE IDE for Web Developers. Version: Indigo Release

I use JUnit 4. For project properties> Java Build Path> Libraries: I have JUnit4 added. Also under the same tab: Maven Dependencies> I have junit-4.8.2.jar

In pom.xml I have:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.8.2</version>
  <scope>test</scope>
</dependency>

Basically, I’m writing unit tests using JUnit in the past few months! All I needed to do was to create a test class, add a test method like below:

@Test
public void testMethod(){
    // Some test code
}

Right click on method, Run As> JUnit Test

That’s all I needed to do to either run my unit test or do Debug As> Junit Test to debug my unit test.

All was fine with the world! Starting yesterday, when I add a new test method in a class I already have and then do: Right click on method, Run As> JUnit Test

Nothing happens! I cannot run or debug any test anymore! Meaning I cannot add any new unit test!

Let me also add that I do a clean build thru Eclipse and Eclipse sees the newly complied class which contains my new test method.

Since none of my configurations changed, I have no idea what went wrong!

Does anybody has any idea? Any help would be greatly appreciated.

C:\Project>mvn eclipse:eclipse
[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-jar-pl
ugin/2.3.2/maven-jar-plugin-2.3.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-jar-plu
gin/2.3.2/maven-jar-plugin-2.3.2.pom (6 KB at 10.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin
s/21/maven-plugins-21.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins
/21/maven-plugins-21.pom (13 KB at 27.8 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/20/mave
n-parent-20.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/20/maven
-parent-20.pom (25 KB at 50.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-jar-pl
ugin/2.3.2/maven-jar-plugin-2.3.2.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-jar-plu
gin/2.3.2/maven-jar-plugin-2.3.2.jar (32 KB at 71.4 KB/sec)
[INFO]

[INFO] Building myProject 3.0

[INFO] >>> maven-eclipse-plugin:2.8:eclipse (default-cli) @ myProject >>>
[WARNING] The artifact commons-email:commons-email:jar:1.1 has been relocated to
org.apache.commons:commons-email:jar:1.1
[INFO]
[INFO] --- xmlbeans-maven-plugin:2.3.3:xmlbeans (default) @ myProject ---
[INFO] All schema objects are up to date.
[INFO]
[INFO] <<< maven-eclipse-plugin:2.8:eclipse (default-cli) @ myProject <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.8:eclipse (default-cli) @ myProject ---
[INFO] Using Eclipse Workspace: null
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAIN
ER
[WARNING] While downloading commons-email:commons-email:1.1
This artifact has been relocated to org.apache.commons:commons-email:1.1.
Commons Email has been reassigned to the
org.apache.commons group as per the Maven 2 standards.

[INFO] Creating maven-eclipse.xml Ant file to handle resources
[INFO] Creating external launcher file
[INFO] File C:\myProjectProject\.project already exists.
Additional settings will be preserved, run mvn eclipse:clean if you want
old settings to be removed.
[INFO] Wrote Eclipse project for "myProject" to C:\myProjectProject.

[INFO] BUILD SUCCESS

[INFO] Total time: 6.823s
[INFO] Finished at: Tue Mar 13 13:16:52 PDT 2012
[INFO] Final Memory: 9M/152M
blueSky
  • 649
  • 5
  • 13
  • 31
  • Does it run externally from eclipse? Did your eclipse test runner accidentally change (Run configurations > Test tab - Test runner should be JUnit4, not Junit3) – Ann Addicks Mar 13 '12 at 18:11
  • In Run Configurations I have: Test runner: JUnit 4. However, I tried to add new test, by: clicking on "Press the 'New' button to create a new configurations of the selected type" to see if I can run any new unit test method that way, but it does not let me add any! – blueSky Mar 13 '12 at 18:14
  • Is there anything in the Error Log (Window->Show View->Error Log)? If so, can you post the error/Exception here? – Matthew Farwell Mar 13 '12 at 19:04
  • I wish there was an error! There is none! Basically Eclispe does not let me to launch any new test method or test class. – blueSky Mar 13 '12 at 19:58
  • I ran mvn eclipse:eclipse from command line, nothing changed, but I'm wondering if anybody sees anything wrong with it? I added all comments in the original post. – blueSky Mar 13 '12 at 20:51
  • Do you import your project as a Java or Maven project? you can tell this by check the small project icon in Package Explorer: J on the top right for Java or M on the top left for Maven. – yorkw Mar 13 '12 at 21:34
  • I had this project imported as Maven project. Deleted the project from Eclipse, imported it again - like before - as Maven project and get this error: "An internal error occurred during: Eclipse has encountered problems with maven dependencies: "Updating Maven Dependencies". org.apache.crimson.tree.XmlDocument.getXmlStandalone()Z – blueSky Mar 13 '12 at 22:22
  • I cannot even build thru Eclipse any longer! Receive the followingerror: PDT: Build errors for M; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources (default-resources) on project M: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources failed. – blueSky Mar 13 '12 at 22:23
  • I tried to import it as a Maven project but since it encountered errors, I think it was imported as a Java project b/c I see the J on top of the project. On Project Properties> Java Build Path> Add Library> I tried to add Maven Dependencies; it has Maven Managed Dependencies but does not let me add it. – blueSky Mar 13 '12 at 22:32
  • Try delete your project in Eclipse, run a mvn clean:clean followed by mvn eclipse:clean from command-line (this will clean all IDE generated files like .project and .classpath), then fresh-import it either as Java or Maven project, check out answer [here](http://stackoverflow.com/questions/9457860/importing-projects-into-eclipse/9460188#9460188) to see how to do it properly, see if this helps you out. – yorkw Mar 14 '12 at 00:20
  • my test didn't run cause Eclipse selected the "Junit5" Framework, after i changed manually to "Junit4" in "Run configurations" it worked... – Pierpaolo Piccoli Jul 01 '22 at 13:12

7 Answers7

5

My advice is reinstall Eclipse, some config must have broken. Chuck Norris can figure out these problems very quickly but for the rest of us reinstall is usually a good way to go.

jabal
  • 11,987
  • 12
  • 51
  • 99
3

I got this working by recreating the workspace - not able to figure out what was wrong with it. Just here making a note that reinstalling eclipse is not needed, the problem is with a corrupt workspace.

eis
  • 51,991
  • 13
  • 150
  • 199
3

I had a similar problem after i had to force quit my eclipse. After starting no junit test cases will run. It will just say finished after 0 seconds. I went to the /{workspace}/.metadata/.plugin folder and deleted the two junit plugins folder. After restarting eclipse I was able to run junit test cases.

Sumit
  • 1,139
  • 1
  • 9
  • 14
0

The following solved my problem in Luna Eclipse.

Go to project properties > Java Compiler > Classfile Generation. The option "Add line number attributes to generated class files (used by the debugger)" must be checked.

Robert
  • 5,278
  • 43
  • 65
  • 115
0

I really didn't want to blow away my workspace and reconfigure a new one. I eventually discovered why telling Eclipse to run JUnit tests did nothing without an error message or any apparent clue.

Looking at > Build Path > Configure Build Path... > , I see my project lists two other projects I've also imported into the IDE and those projects are currently in a closed state as can be seen in the Project Explorer view.

Just opening those other projects resulted in my project responding as expected to my requests to run a JUnit test. I suppose I could have alternatively removed those projects as listed dependencies to my current project's Build Path setup. But I have them there so that clicking on class methods in code will take me to that source code instead of seeing .class file byte code.

Matthew Kuraja
  • 401
  • 4
  • 7
0

If you have multiple JDKs installed, try selecting a different JDK for executing the JUnit tests. Try the same that runs Eclipse.

I was having the same symptom using eclipse 2022-09. I currently have OpenJDK 11 and 17 installed with some projects still on JDK 11 as imported by maven.

Today running JUnit tests stopped working while run as Java was fine. Removing the project specific JDK setting worked for me.

Benjamin Peter
  • 4,009
  • 2
  • 23
  • 23
0

I tried many ways... finally had to uninstall Eclipse and install it again. Jabal: thanks for the advice! I got the Eclipse Indigo for 64 bit; installing that, was kind of painful too! After getting so many errors and a few times install and uninstall, found out that it only works with JDK7! Although the documentations mentions it should also work with JDK6, but did not for me. Anyway, the unit testing is back to normal which is nice.

blueSky
  • 649
  • 5
  • 13
  • 31