I've downloaded Junit version 4.10 and loaded the jar via the build path but I seem to get this error message when running a Junit test in Eclipse:
Error: Could not find or load main class org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
My Test class is the following:
import org.junit.*;
import static org.junit.Assert.assertEquals;
public class InternetConnectTest {
#Test
public void testConnectMethod(){
InternetConnect net = new InternetConnect("www.google.com");
assertEquals("Result", "www.google.com", net.url);
}
}
I came across this after I updated java versions: "junit: could not load main class 1.1". Go into the eclipse external tools configurations, open the entry for the ant file you are running, then go to the JRE tab, and select "Separate JRE", also making sure your new jre is correctly listed in the Installed JREs...for me, this took care of it.
This is an Eclipse error message. It seems your installation is corrupted. Try using a fresh installation of Eclipse.
Before trying a fresh install i just restarted eclipse and it did the trick.
I just had the same problem.
I relaunch Eclipse with the "-clean" option, and it did the trick too.
Edit:
How to run eclipse in clean mode? and what happens if we do so?
Related
I want to build a REST Service with Java Spring and followed this guide successfully.
After creating a new gradle project i copied the build.gradle file and started everything with gradle buildRun. It is all woring well, except that Eclipse underlines imports, variable declararations, standard
datatypes as unresolveable.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
For example are in this class String, SpringApplication, SpringBootApplication, Application and org.springframework marked as unresolvable. However Exlipse resolves them just fine. I hope someone can
tell me what i have to change, error detection is quite hard right now (:
The platform is:
Eclipse IDE for Java Developers
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
OS: Linux, v.4.16.13-2-ARCH, x86_64 / gtk 3.22.30, WebKit 2.20.3
I had this issue before with Spring (although it was with with Maven) and I was able to resolve it by updating my Maven project and running a clean build. Check and see if it possible to "refresh" your gradle build/update dependencies:(For me it was Right-click -> Maven -> Update Project), and also try running gradle clean first, then build it to see if leftover artifacts are causing the issue.
If you get a "Could not find or load main class" or an error like that from Spring later, make sure your directory structure (from the project) is src/main/java/hello, with hello being the package containing your class files.
When I attempt to run a sample TestNG class in Eclipse with Java 1.7.0_79 I get the following errror:
Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -protocol
at com.beust.jcommander.JCommander.parseValues(JCommander.java:742)
at com.beust.jcommander.JCommander.parse(JCommander.java:282)
at com.beust.jcommander.JCommander.parse(JCommander.java:265)
at com.beust.jcommander.JCommander.<init>(JCommander.java:210)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:162
I have tried installing TestNG through the Eclipse store, when that didn't work. I uninstalled and did it through the www.beust.com/eclipse site.
My class doesn't show any errors, but my project does have a question mark in the lower-left part of the image.
I thought it was because I was missing the jcommander.jar. So I've even gone and tracked that down and included it in my libraries.
The weird thing is, is that I am running the same configurations on my Windows PC and was able to get TestNG scripts running, but when I go through the same setup on my Mac, I get the error.
This is the code I'm trying to run:
import org.testng.annotations.Test;
public class NewTest {
#Test
public void testMethod() {
System.out.println("First TestNG test");
}
}
Make sure you added the jcommander.jar file to your classpath if you are using a project without maven. Make sure your project structure has a "TestNG" library that has only one testng.jar file inside it.
I need to write a short test for some Java code. I used CTRL+SHIFT+T to generate one with IntelliJ, and selected "Groovy JUnit" as the testing library, then wrote the following test:
package util
class FibonacciHeapTest extends GroovyTestCase {
FibonacciHeap<Integer> heap
void setUp() {
super.setUp()
heap = new FibonacciHeap<>()
}
void testAddInOrder() {
testForItems 1..1000
}
private void testForItems(Range<Integer> items) {
items.each {heap << it}
assertEquals heap.size, items.to
items.each {assertEquals heap.remove(), it}
}
}
However, when I right click on the test case in the project window, I don't get the "Run All Tests" option that I normally do with JUnit tests, and the compiler throws the following error:
Information:2/4/15 8:15 PM - Compilation completed with 2 errors and 0 warnings in 2 sec
/home/patrick/IdeaProjects/hackerrank/src/test/java/util/FibonacciHeapTest.groovy
Error:(3, 1) Groovyc: unable to resolve class util.FibonacciHeap
Error:(9, 1) Groovyc: unable to resolve class GroovyTestCase
Trying to import GroovyTestCase or FibonacciHeap manually causes the same error. IntelliJ does not add any import statements when I let autocomplete finish the names for me, like it usually would with Java code.
What am I doing wrong?
This worked for me :
Open Gradle window (on right side in my case)
Click on refresh button
Done
I had a similar problem with creating test classes in IntelliJ, and it was solved when creating a new directory outside of the com.company folder (where I had the class I wanted to test).
Create a new directory for the test classes on the same level as your src folder
Right click on your new test directory, and "Mark directory as" --> "Test Resources Root"
Now create a test class, which should automatically be added to your test directory.
Build -> Rebuild project in the IDE itself (as opposed to maven, in my case) did it for me.
In my case, what I did to resolve the issue was rather simple.
Close IntelliJ
Open the attached homepage...
Remove your project by clicking on the x then...
Click on Import Project, Navigate to the build.graddle file of your project and open.
That was it and all the Red highlightings disappeared.
maybe you need add groovy-all rather then groovy,such as :
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
You have to configure Groovy SDK first. See the screenshot
More detailed description in the official document: Configuring Global, Project and Module SDKs
As #sman591 pointed out in a comment, if you are getting the error:
groovyc: unable to resolve class groovy.util.GroovyTestCase
and you already have groovy as a dependency then you are probably just missing the junit dependency.
In IntelliJ IDEA I re-imported the project. It worked then.
I closed idea. I removed .idea folder in the project. And I imported the project.
Then I needed to set up Groovy, see previous answers, mark test directory as test source in all modules of my project.
I was selecting the root folder which had build.gradle file in it, but it didn't work.
Steps followed are similar to #Pila
close the project from intellij
remove .idea, log, out folders
go to intellij dashboard
import project from existing resources
select build.gradle file <-- this is important
now you should see all the tasks are getting build in the background, and once build is finished all red lines are gone.
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.
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.