Mike
Mike

Reputation: 60771

JUnit4 + Eclipse "An internal error occurred during Launching"

I'm trying to run JUnit4 test cases on Eclipse 3.4.2 but it's not even starting for me. I have the junit-4.7.jar in my build path and the test application.

Here is a simple example that illustrates my problem

package test;
import org.junit.Before;
import org.junit.Test;

public class UTest {    
    @Test
    public void test() {
    }

    @Before
    public void setUp() throws Exception {
    }
}

This compiles fine

Then I do "Run JUnit Test case" from Eclipse and I get an error dialog with this message

"Launching UTest' has encountered a problem
An internal error occurred during: "Launching UTest".
java.lang.NullPointerException

What causes these NullPointerExceptions? What am I doing wrong?

Upvotes: 19

Views: 32962

Answers (10)

OpenSource
OpenSource

Reputation: 2257

Your code works fine for me.

Eclipse Version: 3.4.1 Build id: M20080911-1700

I right click on the .java file RunAs JUnit Test. This would indicate the problem is caused by an Eclipse configuration problem, not a code problem.

Upvotes: 1

Apurva Sharma
Apurva Sharma

Reputation: 301

If you are using Android and its associated plugins, then Android only supports JUnit 3.

I resolved the problem by selecting Test Runner as JUnit 3.

In my class, JUnit 4 is added in the build path->libraries.

Then to run the test file, go to: Run As -> Run Configurations then select the corresponding test.java file and select Test Runner accordingly(whether it is JUnit 3 or 4).

Upvotes: 1

Eric Leschinski
Eric Leschinski

Reputation: 153912

This error In eclipse can be caused if you are also using the Android Development Kit plugins:

"Launching UTest' has encountered a problem
    An internal error occurred during: "Launching UTest".
    java.lang.NullPointerException

Can be caused if you are loading a normal Java project into an Eclipse instance with android ADT plugins installed and enabled. In this situation, Eclipse looks for "Android" project files, and doesn't find any. So it says: "NullPointerException".

So to fix it, re-download Eclipse without the ADT Plugin: https://www.eclipse.org/downloads/

Then re-import your project fresh. And the junit tests run without a problem.

Many people hate eclipse for it's enigmatic error messages. It's like we are back in the 1950's punch card world, where there are no error messages. The program just halts and undefined behavior occurs.

Upvotes: 2

Mike
Mike

Reputation: 60771

I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.

Upvotes: 4

Joaquin De La Sierra
Joaquin De La Sierra

Reputation: 481

What worked for me after trying everything:

  1. Go to help
  2. Install New Software
  3. Work with: Juno
  4. Programming languages (expand it)
  5. Install Java Development Tools
  6. Restart

It works :)

Upvotes: 32

Sam
Sam

Reputation: 42387

None of the given answers here worked for me, so I ended up just installing and using InfiniTest instead. It doesn't have this problem, and it also runs the tests automatically so I can focus on my work.

Eclipse with Infinitest showing a red "tests failed" status message and the corresponding assertion error in the "Problems" tab

Upvotes: 3

myked
myked

Reputation: 71

I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:

  1. Removed my .project file and the project from Eclipse.
  2. Created the project again.
  3. Everything was working.

The problem seemed to be in the .project file where there were some references to CDT Builder and were not there in the new .project file.

Upvotes: 1

This worked for me:

  1. create another copy of the test class (CopyOfUTest.java)
  2. run the copy to make sure it passes
  3. go into Run > Run Configurations
  4. under JUnit, find the run configurations for the original class and the copied class
  5. right click and delete the configuration of the original class
  6. rename the configuration of the copied class to the original configuration name
  7. delete the copied class from the project

Upvotes: 3

aryaxt
aryaxt

Reputation: 77596

Thanks that solved my problem too. The problem started when i removed an old simulator, and created a new one. Fix: Like the OP says remove the workspace, make sure to keep the projects inside it :) then import them back to eclipse "Sound like a lot of work" ? Took me less than half a minute !!!

Upvotes: 1

Stephen C
Stephen C

Reputation: 718836

Have you looked in the Eclipse error log? You can see it by opening the "Error Log" view.

http://help.eclipse.org/help32/topic/org.eclipse.pde.doc.user/guide/tools/views/error_log.htm

Upvotes: 2

Related Questions