Reputation: 60771
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
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
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
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
Reputation: 60771
I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.
Upvotes: 4
Reputation: 481
What worked for me after trying everything:
It works :)
Upvotes: 32
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.
Upvotes: 3
Reputation: 71
I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:
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
Reputation: 39
This worked for me:
Upvotes: 3
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
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