I am executing a junit test case
I got the following error,
A fatal error has been detected by the Java Runtime Environment:
Internal Error (classFileParser.cpp:3174), pid=2680, tid=2688
Error: ShouldNotReachHere()
JRE version: 6.0_18-b07
Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode windows-x86 )
Can any body please suggest the solution to resolve
I got the same problem, but with alot of googling I found the answer! See this page
Quote from the link:
# An unexpected error has been detected by Java Runtime Environment:
#
# Internal Error (classFileParser.cpp:2924), pid=5364, tid=6644
# Error: ShouldNotReachHere
That's because we are using Android's JUnit stub implementation. Go to Run -> Run As -> Run configurations again and in the recently created JUnit configuration Classpath's Bootstrap Entries remove Android Library
Then Add Library, using Advanced... button, and add JRE System Library and JUnit 3
Apply and Run
Try this, it worked for me.
You'll need to take this up with Sun -- looks like a JVM bug to me. If it's reproducible, you should be able to run java in such a way as to generate more details (e.g. -verbose, etc). If you can reduce it to a minimal case that triggers the bug (source code always helps!), that also goes a very long way.
http://java.sun.com/developer/technicalArticles/bugreport_howto/index.html
http://bugreport.sun.com/bugreport/crash.jsp
In the meantime, you might want to try it with a different JVM implementation (maybe even an older patch level of the Sun JRE).
Go to Run As -> Run Configurations... and select the configuration you are using.
Select the Class Path tab and select BootStrap Entries.
Click on Advance, then Add Library and select JRE System Library.
Bring it up and make it the first entry in the BootstrapEntries List.
Apply and Run...
Another possible explanation: hardware failure. Ruled out if you can reproduce the error on different machines.
I resolved this by
Quit eclipse
Delete the bin and gen directories in your project
Start eclipse
Rebuild your project
I just recently found solution for this issue that was posted by devdanke:
"As of 11-July-2010 and Android 2.1, the work around I use is to segregate tests into different classes. Any test(s) that don't call any Android APIs go into their own classes. For each of these classes, I remove the reference to Android in their Run Configurations, Classpath tab."
The problem with having it configured class by class is then is not possible to run all tests in project. Better approach is creating 2 test projects with different sets of libraries.
Standard Android JUnit Test project can be created following link, and sample test class looks like:
import android.test.AndroidTestCase;
public class ConverterTest extends AndroidTestCase {
public void testConvert() {
assertEquals("one", "one");
}
}
Then JUnit Test project can be converted from Android JUnit Test project by removing Android Library from project build path, and adding JRE System Library, and JUnit 3 library, and sample test class looks like:
import junit.framework.TestCase;
public class ConverterTest extends TestCase{
public void testConvert() {
assertEquals("one", "one");
}
}
I have had a similar problem, I found it was because I had generated a new activity with a main[] stub entry. Once I deleted the main[] code from the new activity templatye the error went away.
YMMV
This could be a JVM bug; see #Zac's answer. But it could also be that your junit test case is causing a corrupted bytecode file to be loaded. Try rebuilding all your .class files, and if that does not fix the problem try refetching any external libraries that your code depends on.
Do you run on a supported platform (Windows, one of a few Linux versions?) If not, that is the first to try.
If you ARE on a supported platform, then downgrade to _17 and see if THAT helps.
Then make a bug report to Sun and hope they will fix it someday (unless you want to give them money for fixing it faster).
Go to Run As -> Run Configurations->classpath->BootStrap Entries
Click on Advance, then Add Library and select JRE System Library as a first entry.
Apply and Run...
I am not sure whether you were able to reach the solution for your problem or not but your question just popped up while I was searching for the solution for the same problem I am facing. And I got one solution from the stack itself, so just thought to share a link with you if that aids you by any means. The link is as below:
Can't run JUnit 4 test case in Eclipse Android project
Another possible reason (for future references):
I had accidentally copied in a main method in my code, causing Eclipse to recognize the project as a java application, thus launching it with that configuration.
To solve it I went into Run > Run Configurations... and then changed from my presumed main in java application to the main activity of my android application simply by choosing it in the left column.
Related
I'm a beginner in Java and am trying to run my code using IntelliJ that I just installed as my IDE with JDK 1.7. The following piece of code keeps does not even compile and keeps giving me the error:
Error: Could not find or load main class libTest
Code
import java.lang.Integer;
import java.lang.String;
import java.lang.System;
import java.util.*;
class book {
private String name = "trial";
private int bookCode=1;
private int issued=0;
public void Issue(){
if(issued==0) {
issued=1;
System.out.println("You have succesfully issued the book");
}
else {
System.out.println("The book is already issued. Please contact the librarian for further details");
}
}
public int checkCode() {
return bookCode;
}
String readName() {
return name;
}
public void setName(String newName){
name=newName;
}
public void setBookCode(int newCode){
bookCode=newCode;
}
}
class library {
private ArrayList books=new ArrayList();
public void getList(){
for(int bk:books){
String bName=books(bk).readName();
System.out.println((bk+1)+") "+bName);
}
}
}
public class libTest{
public static void main(String[] args){
library newLib= new library();
System.out.println("code working");
}
}
Is there any change that i have to make in the compiler settings?? Or is it the code.
This might help:
1) "Build" menu -> "Rebuild Project".
Sometimes Intellij doesn't rewrite the classes because they already exist, this way you ask Intellij to rewrite everything.
2) "Run" menu -> "Edit configuration" -> delete the profile -> add back the profile ("Application" if it's a Java application), choose your main class from the "Main Class" dropdown menu.
3)"Build" menu -> "Rebuild Project".
If none of the above answers worked for you, just close your IntelliJ IDE and remove the IntelliJ IDE file and folder from the root of your project:
rm -rf .idea *.iml
Then open the project with IntelliJ. It must work now.
For me the solution was to fix the output directory under project settings. Before I was using just "target" for the Project compiler output. Instead I updated it to have a full path e.g. D:\dev\sigplusjava2_68\target
I had this problem and I tried everything under the sun that I could think of and on this site.
None of my Java classes were being picked up after I pulled from a remote branch. All the classes had red Js by their names in the Project Hierarchy, not blue Cs.
In the end, I tried to follow this tutorial and a few steps in tried something not described and fixed the issue:
https://www.jetbrains.com/help/idea/creating-and-managing-modules.html
Here's what I did:
Goto File | Project Structure, or press Crtl+Shift+Alt+S
Select Modules under the Project Settings section.
In the Sources tab click Sources on the 'Mark as:' line.
Click the Apply button.
For some reason, all my classes then had blue C's.
Someone with a better understanding of how IntelliJ and/or IDE's might be able to explain the phenomenon, but all I know is now it can see all the classes and more importantly the main one, and run.
Invalidate cache and restart your IntelliJ, it worked for me.
Explicitly creating an out folder and then setting the output path to C:\Users\USERNAME\IdeaProjects\PROJECTNAME\out
seemed to work for me when just out, and expecting IntelliJ to make the folder wouldn't.
Also try having IntelliJ make you a new run configuration:
Find the previous one by clicking
then remove it
and hit okay.
Now, (IMPORTANT STEP) open the class containing your main method. This is probably easiest done by clicking on the class name in the left-hand side Project Pane.
Give 'er a Alt + Shift + F10 and you should get a
Now hit Enter!!
Tadah??
(Did it work?)
File > Project Structure > Modules > Mark "src" folder as sources.
This should fix the problem. Also check latest language is selected so that you don't have to change code or do any config changes.
I know this was asked a while ago, but I was just stumbling over this issue and thought my findings might help others. As pointed out, the error message is basically a result of the out folder. That's because, when you're trying to run the program, it compiles the code first, and puts the compiled result to the out location, and then it tries to load the compiled code from the out location. If the compiled code is not in the location expected, you'll get the error.
The point I'm particularly wanting to share is that some times, the code is not compiled (built), even though your run configuration specifies "Build" in the "Before launch" section of the configuration panel.
When can this happen?
One situation that can cause this to happen is if you're using modules and you manually delete the module out directory. For example, if I have a module named "foo", there should be a directory named foo under out/production. If you manually delete it, the build system may not know that it needs to be rebuilt.
Even worse, if you select Build | Build module 'foo', it still may not rebuild the module. If that's the case, you should select a file in the module, for example 'bar.java' and then select Build | Recompile 'bar.java'. Now the out directory out/production/foo should be restored.
Since IntelliJ typically knows about any changes going on, this surprised me, and took me a little time to figure out, so I thought I'd share.
Check your class module : I have encountered this problem with intellij :
I have a maven multi-module project, the problem is that i runing a class which not exist the module within the configuration, so my problem is fixed by setting the right module ("edit configuration" -> "use class of module")
may this help you
I had to mark the "src" folder as "Sources". After restarting IntelliJ and rebuilding the project I could run the project without further issues (see screenshot).
Edit: You can access the "Project Structure" tab via File->Project Structure or by pressing Ctrl+Shift+Alt+S.
I ran into this problem when my Java class was under src/main/kotlin. After I moved it to src/main/java, the problem was gone.
I have faced such problems when the class is in the default folder, i.e. when the class does not declare a package.
So I guess using a package statement (eg. package org.me.mypackage;) on top of the class should fix it.
Open Modules Tab (Press Ctrl+Shift+Alt+S). I had two modules under one project. I've solved the problem after removing the second redundant module (see screenshot).
After creating your project in intelliJ, try running the following command:
mvn package
I have tried all the hacks suggested here - to no avail. At the end I have simply created a new Maven application and manually copied into it - one by one - the pom.xml and the java files and resources. It all works now. I am new to IntelliJ and totally unimpressed but how easy it is to get it into an unstable state.
Invalidating cache didn't work.
I edited the main class java file with a dummy change and ran it. It worked.
In my case the problem seemed to be related to upgrading IntelliJ. When I did this I overwrote the files from the old IntelliJ with the files from the new IntelliJ (2017 community to 2018 community). After that all of my projects were broken. I tried everything in this thread and none of them worked. I tried upgrading gradle to the latest version (4 to 4.8) and that didn't work. The only thing that worked for me was deleting the entire IntelliJ folder and reinstalling it. All of my projects worked after that.
I have tried almost everything suggested in the answers here, but nothing worked for me.
After an hour of just trying to run my application, I noticed that my project's path included non-ASCII characters (Arabic characters). After I moved my project to a path with no non-ASCII characters, it executed just fine.
Goto File-> Invalidate Caches and Restart .
Else delete rm -rf .idea *.iml
and restart InteliJ
You can run the maven command on the pom.xml file in your project directory:
mvn clean install
For me - i tried few of the options above, did not work. Then i just renamed my Application class and that probably forced intelliJ to build a fresh jar and error message started to change. Then i renamed it back and it worked.
Mark the directory as a source directory. Opened via Ctrl+Shift+Alt+S
modules.xml with wrong content, I don't know what's matter with my IDEA.
I inherited a bunch of .JAVA files from elsewhere and couldn't figure out how to get them to work in any IDE. Ultimately I had to go to the command line where the Main.JAVA file was and run javac Main.java. This created a bunch of .CLASS files. The IDE's were then able to figure out what to do.
I got this error when using Scala/SBT. IntelliJ could not find the main class, even though everything was set up correctly.
My solution: delete the <user>/.sbt/<version>/plugins/target folder, then restart IntelliJ.
You probably would have specified a wrong package and the package hierarchy would not be right. Look below
The ide would highlight the wrong path in that case.
I'm using IntelliJ with Spring and my main class is wrapped in a JAR.
I had to mark the 'Include dependencies with "Provided" scope' in the Run/Debug configuration dialog
We are at File/Project Structure..
Answer might be:
Folder indicated as "content root" needs a child folder where the code is.
Plus find the button that marks code as excluded and not.
Not to be confused with tickbox that states excluded without telling in what phase and what**
Is it compiler exclude or runtime exclude? You are doomed to test and lot.
So no that tickbox but icons and colors.
As an idea we need to crack how it was originally thought to work. They never got it to work in first place and started add things in premature codaculation style.
It has been so many years and you cannot expect any improvement.
But as cure we can hack out some way to get it right every time.
Another thing you can check here is the actual command that is being passed to the JVM and make sure it looks OK. Scroll to the top of your Run console, it should be the first line.
Spaces in your Run Configuration VM Options field will malform the app startup command and can result in this error message
-DsomeArgument="arg with space must be quoted"
I am working with Kotlin but am guessing the problem is the same. I would start a project, create a single file and add main to it and the IDE couldn't find the main.
I tried the things in this list and none worked. I finally mentioned my frustration on one of the IntelliJ pages and was contacted. Of course, it worked fine for IntelliJ. After a couple of days back and forth, I noticed that the highlight function wasn't working and mentioned that. It turned out something was wrong with the IDE settings. I still don't know specifically what was wrong but the fix in my case was to reset the IDE settings. File->Manage IDE Settings->Restore Default settings.
After this, the green triangle start icon became visible to the left of my main function and things continued to work normally for subsequent projects.
Thanks to Konstantin at JetBrain's support for his patience.
I am creating a program along the lines of Codingbat.com.
During Runtime, it needs to compile code, and then execute it. This has all been handled.
Currently, I am forced to use the JavacTool, which requires it to be packed alongside.
I have 2 basic questions:
1) How can I stop the ToolProvider.getSystemJavaCompiler() from returning null when ran from an executable jar?
2) If the above is not possible, is there a way to add the jar of com.sun.tools.javac.api.JavacTool; without having it as a referenced library, so that it acts like a regular import?
Thanks for answering this, if you would like, I could upload the Jar with the referenced library, and the jar without it.
Just to be clear, the one with the referenced library works, but it is way to large, and slower then the jar that is ran through eclipse, that uses the JavaCompiler, not the JavacTool
Thanks
Edit:
I am pretty sure this is possible with java as I have seen it before, yet forget where and how.
I suspect it's just a problem of which version of Java you run. If you run the version which comes with the JRE, it won't have the tools available. If you run the version which comes with the JDK, it will.
As an example, here's a short but complete program:
import javax.tools.*;
public class Test
{
public static void main(String[] args)
{
System.out.println(ToolProvider.getSystemJavaCompiler());
}
}
Running it with the JRE version of java.exe on my laptop:
c:\Users\Jon\Test>"\Program Files\java\jre7"\bin\java Test
null
And now with the JDK:
c:\Users\Jon\Test>"\Program Files\Java\jdk1.7.0"\bin\java Test
com.sun.tools.javac.api.JavacTool#441944ae
So try explicitly specifying the a Java binary associated with the JDK.
So you already know that all your users will have a JDK installed and you know how to find the classpath of the JDK when you're in your Java program. You don't need to load a DLL. You need to load the com.sun.tools.javac.api.JavacTool class in tools.jar. See How to load a jar file at runtime on how to load tools.jar
I am unable to run the following code in Eclipse (Eclipse IDE for Java Developers, Version: Indigo Service Release 1, Build id: 20110916-0149), and I think that I may have a configuration problem in Eclipse (but I do not know what or where):
class Saluton {
public static void main(String args[])
{
String greeting = "Saluton mondo!";
System.out.println(greeting);
}
}
I am also running against Java 6 (1.6.0_29-b11-402) on Macintosh 10.7.2.
When I run this, I get the error:
"java selection does not contain a main type"
but I am pretty sure that my class is written correctly...? I have looked this error up, and cannot explain this problem so far.
TIA for any thoughts or opinions!
I think you have to make your class public, otherwise it won't work?
EDIT: My previous answer was incorrect. The JLS says you can declare arrays with the brackets at either end. See here for some examples. My mistake.
Have you verified your configuration in Eclipse such that it knows where to find the Java compiler, and a JVM? You can check the project-specific libraries by right clicking the project and going to Properties, Java Build Path
You can also check the JRE's installed by clicking Window, Preferences, Java, Installed JREs. Make sure the JRE you wish to use is listed here and that the path is correct.
Another solution (simple and direct):
In Eclipse: File -> Restart
Right click your class Saluton and choose Run as --> Java Application.
It should work.
Ok, so I'm a fellow noob, and I came here because I had this problem. I checked all my class paths and everything, and they were correct. I had actually been putting all of my files in the JRE System Library Folder, instead of the source folder. I'm not sure if this was you'r problem, but it seemed to work for me when I moved the code files into the src folder.
I took the long way around to solve this; eventually I created a package within my project and added my source code to that package and it compiled and ran! I am learning that Wizards rule!
It will work if you make your class as public !
When I attempt to run the following test in IntelliJ IDEA I get the message:
"!!! JUnit version 3.8 or later expected:"
It should be noted that this is an Android project I am working on in IntelliJ IDEA 9.
public class GameScoreUtilTest {
#Test
public void testCalculateResults() throws Exception {
final Game game = new Game();
final Player player1 = new Player();
{
final PlayedHole playedHole = new PlayedHole();
playedHole.setScore(1);
game.getHoleScoreMap().put(player1, playedHole);
}
{
final PlayedHole playedHole = new PlayedHole();
playedHole.setScore(3);
game.getHoleScoreMap().put(player1, playedHole);
}
final GameResults gameResults = GameScoreUtil.calculateResults(game);
assertEquals(4, gameResults.getScore());
}
}
The full stack trace looks like this...
!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:152)
at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:136)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
Process finished with exit code -3
This problem happens because Android Platform (android.jar) already contains JUnit classes. IDEA test runner loads these classes and sees that they are from the old JUnit, while you are trying to use annotated tests which is a feature of the new JUnit, therefore you get the error from the test runner.
The solution is simple, open the Project Structure | Modules | Dependencies, and move the junit-4.7.jar up, so that it comes before Android 1.6 Platform in the classpath. Now the test runner will be happy as it loads the new JUnit version.
my module is a java library module, so changing JRE to 1.8 java solved the issue.
Or, you can also do it globally via Module Settings > SDK Location > JDK, specifying Oracle's JDK 8 instead of Android SDK's copy.
I had this problem with a multi module project (libgdx). One module is pure Java and has tests.
My solution was to set "use alternative JRE" to "Java 1.8" in the run configuration of my unit tests. This makes sure no android.jar is on the classpath and the junit 4.x runner is used.
I got the same error when creating both Unit Test and Android Instrument Test in Android Studio 1.4+ and it started to get confused. To avoid this error make sure your test class is fall under Android Tests on Run/Debug Configurations
Make sure you follow the instruction properly https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
Make sure Test Artifact in Build Variants is set to Android Instrumentation Tests
Click menu Run > Edit Configuration
Make sure your class/method name is inside Android Tests instead of JUnit
If it is in JUnit simply delete the config and right click on the file you want to test and Run again. It will then create the config under Android Tests section and it run on device/emulator.
For Android Studio - starting from Android Studio 1.1 Beta 4, Google has added support for Android Gradle plugin 1.1.0-RC. The new plugin supports Unit Testing through Android Studio using junit 4+.
This is still experimental and there are some manual steps to set this up.
For everyone who is reading this post and still have the same issue with AndroidStudio 1.0. You cannot change the dependency order in AndroidStudio has the IDE re-write them automatically. And, even if you manage to change the order by modifying the .iml file, you will get a "class not found...". This is because the Test output path cannot be set on AndroidStudio.
Actually, there is solution to make AndroidStudio, Junit and Robolectric working together. Take a look at this https://github.com/JCAndKSolutions/android-unit-test and use this plugin as well : https://github.com/evant/android-studio-unit-test-plugin
Works perfectly for me.
For me this problem was caused by an outdated/broken run configuration for the tests. I simply had to delete the configuration, then create a new one and the problem was fixed.
I have got the same error when i have create my own junit package
To fix this, i have added these two lines in my app gradle file as it's explained here :
dependencies {
...
// Required -- JUnit 4 framework
testCompile 'junit:junit:4.12'
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:1.10.19'
}
I got the same message
JUnit version 3.8 or later expected
by a simple beginner's mistake. I had used the same package names and class names on src/main and src/test for a class (the HomeController class in my case):
my-test-project
+--pom.xml
+--src
+--main
+--com
+--example
+--Application.java
+--controller
+--HomeController.java
+--test
+--com
+--example
+--ApplicationTest.java
+--controller
+--HomeController.java <---- same package and class name: not good!
With that, the src/main HomeController class, as well as the src/test HomeController class, had the same full path:
com.example.controller.HomeController.class
The result: any tests that were dependent on the HomeController class have failed.
Either changing the package name and/or the class name has resolved the issue. Here the example, when both, the package name and the class name is changed:
my-test-project
+--pom.xml
+--src
+--main
+--com
+--example
+--Application.java
+--controller
+--HomeController.java
+--test
+--com
+--example
+--test <---- added (optional)
+--ApplicationTest.java
+--controller
+--HomeControllerTest.java <---- changed
Now the fully qualified class names differ. The src/main HomeController class name is:
com.example.controller.HomeController.class
and the src/test HomeHontrollerTest class name is:
com.example.test.controller.HomeControllerTest.class
With the fully qualified class names being unique, the problem disappears.
There are two thing I could imagine to happen
If your IDE tries to start an Android
Junit test that directly runs on the
emulator you can't use Junit4.
If you accidentally used the junit classes provided from the android jar they can't run on a normal jvm because there are only real compiled classes for the android dalvik vm.
This happened to me as well in Android Studio 1.1 - although it should support unit tests without a plugin.
On other machines (same project, same version of AS) I found that when running unit tests, the IDE does not add the android.jar file to the classpath, while in my machine it does.
My best guess was that due to the conversion we did from Maven to Gradle and moving from intellij to AS some cache of settings remained somewhere in my machine that caused android.jar to be added to the classpath.
What I did is to clear all android related caches from my machine (under the c:\users\USRE_NAME folder):
.android
.AndroidStudio
.gradle
.m2
After that I reopened the project and the tests worked.
Still trying to understand what went wrong, but this should do the trick for now.
I had this issue in Android Studio 1.5, because I did not know that I had to switch the "Test Artifact" setting in the "Build Variants" (lower left corner of the main window) from "Android Instrumentation Tests" to "Unit Tests". When you do, you can see an ExampleUnitTest.java file in the Project window.
I had the same problem but for another reason. I was on IntelliJ with a regular java gradle project (not android) but the JDK was set to the Android SDK in Project Structure (was the default JDK for some reasons). This is really dumb but IntelliJ wasn't nice enough to indicate me what's wrong, so I got stuck on that.
This is how I solved it:
Edit Configurations -> Defaults -> Android JUnit -> Add the following to Working Directory:
$MODULE_DIR$
Worked when I update IDEA version to 2021.2.1.
In Android project I had minifyEnabled = true, after I changed it to false everything worked.
If you remove
testOptions {
unitTests.returnDefaultValues = true
}
from your build.gradle it will work
Go to Project Structure -> Platform Setting, change SDKs to 1.8
solved my problem.
I followed CrazyCoder's answer but there was no junit file shown in dependencies. so i downloaded one from http://www.java2s.com/Code/Jar/j/Downloadjunitjar.htm, then added it by pressing the plus button on the right. And it worked
Turning off "Use embedded JDK" in Project Structure/SDK Location is what helped in my case but I don't know exactly what was the reason it was failing in the first place.
Replace your android.jar in libs folder with the latest one.
You can download it from here
In AndroidStudio, Open Project Structure -> SDK Location, you can see JDK location, change use "Use embedded JDK" to you own JDK to apply, then change back to "Use embedded JDK", it's maybe work
In my case, change JRE in Run Configurations dose solve the problem, but when I click the run button next to the test function, the JRE options will reset to default.
Finally, similar to #CrazyLiu 's answer, in Project Structure - SDK Location - JDK, select Embedded JDK. Because there is no checkbox in Android Studio 3.6.
None of the above worked for me (Intellij 2019.3.5
Build #IU-193.7288.26), finally using 're-import all projects' button on the maven pane worked.
For me, i did delete useLibrary 'android.test.runner' line in android {} block at bulid.gradle module file and everything worked fine.
I had the same problem in a Java 11 with Spring project, turns out when I tried to run the test, I put the wrong "shorten command" option.
Using the "JAR Manifest" option fixed the issue.
IntelliJ shorten command options
I was also facing the same issue, after changing into build.gradle it's working fine for me.
change your junit version inside build.gradle to:
testImplementation 'junit:junit:3.8'
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?
What worked for me after trying everything:
Go to help
Install New Software
Work with: Juno
Programming languages (expand it)
Install Java Development Tools
Restart
It works :)
I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.
This worked for me:
create another copy of the test class (CopyOfUTest.java)
run the copy to make sure it passes
go into Run > Run Configurations
under JUnit, find the run configurations for the original class and the copied class
right click and delete the configuration of the original class
rename the configuration of the copied class to the original configuration name
delete the copied class from the project
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.
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
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.
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 !!!
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).
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.
I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:
Removed my .project file and the project from Eclipse.
Created the project again.
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.