I recently installed Eclipse 2020-06 and am using JDK 10.0.2. I wanted to test Eclipse using a simple Hello world program:
package eclispeTest;
public class eclipseTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello");
}
}
But I get the error: Error occurred during initialization of boot layer java.lang.module.FindException: Module eclispeTest not found
One quick fix I see for this to delete the module-info.java file but when I do this I get the error: Error: Could not find or load main class eclispeTest.eclipseTest Caused by: java.lang.ClassNotFoundException: eclispeTest.eclipseTest
I saw one potential fix that told me to go to "Check your project build-path and enable specific output folders for each folder. Go one by one though each source-folder of your project and set the output folder that maven would use."
from: Eclipse - java.lang.ClassNotFoundException
But I am new to Eclipse and have no idea what they are talking about.
I have also noticed that when I open the problems tab at the bottom of Eclipse there is one problem that is repeated about 8 times: Description Resource Path Location Type The project was not built due to "Failed to init ct.sym for C:\Program Files\Java\jre-10.0.2\lib\jrt-fs.jar". Fix the problem, then try refreshing this project and building it since it may be inconsistent eclispeTest Unknown Java Problem
Could someone help me figure out what I should try, with baby steps for how I should do it.
Thank you in advance.
PS in case it helps here is a picture of my Eclipse window after I try to run my code:
EDIT: I made a new java project and below is my java project cration window
(I still got the same error)
Fist of all, In order to work the line " System.out.println("Hello");"
you will require two classes
1)java.lang.System
2)java.io.PrintStream
using above two classes the code runs.you don't have to import these class,because JRE(Java Runtime Environment) automatically does for you.
If you are gettting this error
Error occurred during initialization of boot layer java.lang.module.FindException: Module eclispeTest not found
Which means You didn't setup your "Java project" properly with "JRE"
Let create new project to solve this problem
1)Open Eclipse IDE
2)click FILE (top left most)
3)New
4)java project
5)give you project name (make sure that- "use default location checkbox" clicked)
6)IN JRE section - select use an execution environment JRE(edition as required)
7)Then click finish
This would have solved your problem , go create a Class do your eclipseTest. This time it should work.
java project creation should look like this
I am trying to do my first test-automation with Spock.
I do not want to use maven.
I am using eclipse java EE oxygen 4.7.
I have created a groovy project.
I have added the Spock jar as an external library in the build path configuration.
Spock ist Spock-core-1.1-groovy-2.4.
I have also added geb jar the same way.
However, I am getting this strange error from the automatic build, which I do not understand and I am seeking for help. So far I haven't found anything helpfull.
General error during semantic analysis: Transform org.spockframework.compiler.SpockTransform#xxxx cannot be run org.codehaus.groovy.GroovyException:
Transform org.spockframework.compiler.SpockTransform#xxxx cannot be run at
org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:416) at
org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:972) at
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:633) at
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:609) at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:586) at
org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.processToPhase(GroovyCompilationUnitDeclaration.java:217) at
org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.resolve(GroovyCompilationUnitDeclaration.java:613) at
org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:879) at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:141) at
java.lang.Thread.run(Unknown Source) Caused by: java.lang.NoClassDefFoundError: Unable to load class org.spockframework.runtime.ErrorCollector due to
missing dependency org/junit/runners/model/MultipleFailureException at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:397) at
org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:353) at org.codehaus.groovy.ast.ClassNode.getDeclaredMethods(ClassNode.java:981) at
org.codehaus.groovy.ast.ImmutableClassNode.getDeclaredMethods(ImmutableClassNode.java:105) at
org.spockframework.compiler.AstNodeCache.(AstNodeCache.java:65) at org.spockframework.compiler.SpockTransform$Impl.(SpockTransform.java:
52) at org.spockframework.compiler.SpockTransform.visit(SpockTransform.java:47) at
org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:395) ... 9 more
My code is as simple as you can get. This is the code:
//The error is on the "p" letter of package
package hellowworld
class HelloWorld{
static main(args) {
}
}
Please note that this error only happens when I add Spock jar. The closest question was Spock without maven or gradle, but obviously the problems are different.
I just cut the file from the package directory pasted it out side and then recut pasted in the package back. It worked well and I have no idea why.
This is one of those problems which occasionally arise in Eclipse and most people just won't know why!
The thing to do usually is to try several "strategies" and hope that one will work. If not you have to come back to SO and try to enlist the support of an expert.
One tip: in my experience sometimes it is worth trying "Refresh Gradle" and "Build all" more than once. Not only that, but sometimes trying either of these actually then seems to do nothing... but a couple of seconds later the horrid x in the red box then vanishes like morning mist!
Highlight/select the project in Project Explorer --> right-click --> Gradle --> Refresh Gradle Project
Put cursor in a code file open in the editor, press Ctrl-B (Project --> Build all)
Close all files in editor, close Eclipse and start up Eclipse again
Try the above in various combinations
Reboot and then try the above in various combinations
If this fails to cure it you may need to turn to SO.
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'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?
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'