i use intellij with junit to run tests (new), when i debug my test code for practice, one of the very first lines of code that seems to run is some method called main from package called com.intellij.rt.junit. I've tried clicking on it as well as searching for it open that package or class to see what's inside but i can't find it all. anyone know what it is or where i could find it in intellij and why i can't just access it from the debugger like every other class? i have junit 5.8 installed in maven.
y.bedrov's analysis is quite right.
com.intellij.rt.junit.JUnitStarter is part of IDE. In your case, the IDE is IntelliJ IDEA. You may find the source code in this local path:
/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar
then import the jar package into your own project to read the source code conveniently.
Related
I'm trying to get an existing project working on a new platform (MacOS, M1) with Idea as the IDE. (I'm extremely new to Idea, but I'm getting help from other project developers.)
For a particular module in the project, any attempt to run pretty much any Grails command fails with an exception:
org.codehaus.groovy.runtime.memoize.EvictableCache.getAndPut(Ljava/lang/Object;Lorg/codehaus/groovy/runtime/memoize/MemoizeCache$ValueProvider;)Ljava/lang/Object
I have verified (to the extent I know how) that there's only one Groovy installation on the machine, and it's version 2.4.14 installed by sdkman. (Grails is 2.5.6.) Running the grails command as part of the Idea build (ie, from clicking "Build" or whatever inside the IDE) and running the grails command in the module top-level directory from the command line have exactly the same results.
I don't have much (well, any) experience with grails or groovy, but to me a "NoSuchMethodError" means that some piece of code was compiled against a different version of that class (EvictableCache) than the version that's actually in the jar file when grails runs. There are groovy .jar files in the project directory, but their presence seems to make no difference; it always gets that exception.
I'm using the Azul zulu8 JDK, downloaded from Azul directly. Formerly I had been using a version installed with brew but that made no difference.
Any ideas as to how to locate the .class file with the attempted call to getAndPut() in EvictableCache would be welcome.
edit — as I was looking at the stack traces from running a command, I noticed something. Again, my groovy is 2.4.14, as I can verify with groovy -version. At the top of one of my stack traces (maybe more than one) I see that the attempted call to getAndPut() is coming from a class called AbstractExtensionMethodCache. Well, as far as I can tell, that class did not become part of Groovy until version 3. So clearly something is messed up.
I am trying to test a java library I found online. I'm testing each component separately, and they work correctly on the command line when I do javac *.java followed by java test. This works perfectly fine, but if I try to build the same test.java file in IntelliJ 2017, it seems to build other irrelevant source files also present in the project and fails since they require dependencies that are not present (but I just want to compile and run test.java.)
How can I resolve this?
I don't know anything about the library you are using, so this may or may not work for you...
In the Project panel of Intellij IDEA select the class of the *.java file you want to compile/run.
Right-click, and on the popup menu you should see a couple of entries that look something like this:
Recompile 'Test.java' (That entry may or may not be present.)
Run 'Test.main()' (That entry will be present as long as you have a main() method.)
See the screen shot below for clarification.
Do you see similar entries?...
If so, what happens when you select them?
If not, please update the OP with more information on the error you are getting.
I have a few import statements in my project that are displayed in RED. Intellij shows 'Cannot resolve symbol' errors, and I am not able to autocomplete these classes or their methods. However, when I run my project it runs perfectly fine. This is strange so much so, that lets say I have an import statement
import org.apache.velocity.app.Velocity
It cannot resolve the 'Velocity' class, even though when I do a ctrl+b selecting the 'app' package, it clearly shows the Velocity class:
I am lost in this and I am struggling to code like this. Any help will be appreciated.
Best Regards.
EDIT: In my project, some of the dependencies are also not resolved, although I refreshed my project multiple times. The exact same dependencies are resolved in my colleague's system, who is using the same code-branch and environment as me.
I can see that the unresolved dependencies lie inside the play.sbt package, but are still not resolved. Is there a compatibility issue between Intellij("15.0.2") and SBT("0.13.8" mentioned in build.properties of my app)?
Reimport project using option 'Import project from external model' and choose 'sbt'. In next window choose options like 'use auto-import' and download 'sources for SBT and plugins'.
Ok, so I'm working on a project using IntelliJ and trying to take advantage of its cucumber functionality. I've not worked with the java flavour of cucumber, but IntelliJ seems to want the step definition files in a specific location, relative to the feature files.
I found this: how to define step definitions location for cucumber in intelliJ 12 and other sources that pointed me to been able to add the "glue" property of my run configurations which tells cuke which package to find the step file. So I am at a point where I can run my tests via IDEA. BUT I need to set this every time I run a new test, as Ctrl+Alt+F10 or right click+run test will not start the test with this flag. Also, the ide support is screwed as IDEA doesn't know where the steps are, it doesn't auto complte or Ctrl+Click navigate to steps.
Is there a way to the the IDEA project to always look for steps in a given package both when running the tests and for its auto complete?
Creating self answer for others who might have this problem. My project did not have the steps marked as test source root, and although I DID do this, it was not until I closed and reopened my project that they were picked up. So a simple restart was my answer.
You can set the glue location globally by opening "Edit Configurations -> Defaults -> Cucumber Java -> Glue" and add the package names.
(IntelliJ 12.1.4)
Go File->Settings--> plugins
Install Cucumber for Java plugin
Then you can manage cucumber plugin as shown below
This should redirect you to step definition when you click your test.
Hope this helps
IntelliJ supports a plugin for Cucumber-Java/Groovy. Installing this plugin will enable the navigation from Steps mentioned in the feature file to the Step Definitions.
And after creating the Step Definition, navigation is easily possible
I go in EditConfiguration, Glue section and i put the path from the package above and the package where is your class for steps, ex:
CucumberFramework.stepsDefinitions
It is really nonsense :) but in in my case when IDEA refused to add steps definition automatically due to some plugins installed, e.g. Cucumber for Scala and suggested deleting them that i cant since i need them in other project. So, long story short, to add (Create step definition) you need to create Class in 'glue' dir and some fake Cucumber implementation, build one more time and it resolved my issue.
Background:
When I use IDEA 2018.2
And Java 8
And Cucumber info.cukes:cucumber-java:1.2.4
#When("^I created a Class and put there fake step implementation$")
#And("^I run gradle build one more time :)$")
#Then("^This Class will be able for me from the feature file by ALT+ENTER as usual$")
#And("^It resolved my issue when I was not able to automatically generate step definition$")
I've started working on a large project where the IntelliJ environment has already been set up. The environment includes JUnit, and I can successfully run unit tests. I've seen screens where I can specify the usage of JUnit 3 or JUnit 4, but how can I determine which specific JUnit is being used to run my tests, e.g., JUnit 4.11?
I have already tried "Open Module Settings". When I look at the "Dependencies" tab, I don't see anything relating to JUnit, although I can run JUnit tests.
Which jar is used?
When you run JUnit from IntelliJ, the very first line of the console output displays your classpath. You can use Ctrl+F to find any "junit" references.
junit-rt.jar is a helper library that JetBrains might have written. By opening the jar as an archive with 7-zip, you will find that the only package inside it is under com.intellij
According to Java: Which of multiple resources on classpath JVM takes? the first reference to junit.jar is the one you will use.
What version is that jar?
Once you know which jar is being used, there are a number of ways to find the version. One is to use this code taken from https://stackoverflow.com/a/16729507/1405720
import junit.runner.Version;
System.out.println("JUnit version is: " + Version.id());
Another method might be to open up the jar as an archive and see if you can figure it out from there.
If you are looking for the JUnit libraries that are shipped with IntelliJ have a look at the corresponding jars in the lib/ directory of your Intellij IDEA installation.
For more information on this have a look at the online documention:
http://www.jetbrains.com/idea/webhelp/configuring-testing-libraries.html
http://www.jetbrains.com/idea/webhelp/testing.html