IntelliJ doesn't autocomplete JUnit 5 Jupiter classes - intellij-idea

I have Maven imports for JUnit 5 in an IntelliJ install, and I have invalidated the cache and restarted.
IntelliJ will refuse to autocomplete (CTRL-SPACE) any class nor any static method belonging to classes in the org.junit.jupiter.api. package, unless the class' fully qualified name is spelled out. Even when writing the package for which the class belongs, will not suggest the classes of that package.
IntelliJ version is 2017.2.1. Jupiter version is 5.0.0-RC2, platform is 1.0.0-RC2.
I am unsure how to move on from here. How come this package is the only one that seems to refuse basic completion?
<properties>
<junit.jupiter.version>5.0.0-RC2</junit.jupiter.version>
<junit.platform.version>1.0.0-RC2</junit.platform.version>
</properties>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>

Please check those classes are not in exclude list in File | Settings | Editor | General | Auto Import

You can try to downgrade JUnit 5 to M4 instead of RC2. IntelliJ 2017.2 is based on JUnit 5 M4, maybe that is causing the problem you are facing.

Related

IntelliJ cannot resolve Kotlin stdlib members within bundle

According to the Kotlin docs, there is an OSGi bundle for the Kotlin standard libraries. However, if I replace kotlin-stdlib with this bundle as recommended:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-osgi-bundle</artifactId>
<version>${kotlin.version}</version>
<type>bundle</type>
</dependency>
IntelliJ is no longer able to find any classes or functions from the stdlib (i.e. println):
If I build and run the project (with maven-pax-plugin), everything works fine - it just seems to have broken IntelliJ's analysis capabilities.
How should I properly include Kotlin as an OSGi dependency?
I am using maven-bundle-plugin to build this bundle.
If you remove the type section, it should work:
<type>bundle</type>
The Kotlin OSGi bundle is not a Maven bundle artifact.
For Intellij IDEA 2018.2, works for me, using this way :
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-osgi-bundle</artifactId>
<version>${kotlin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>

JUnit on IntelliJ not working

I tried setting up JUnit 5 on my INtelliJ IDEA Community Edition 2018.2. The jar was downloaded but I am getting Cannot resolve symbol Assertions on importing
import static org.junit.jupiter.api.Assertions.*;
Error
Are you trying to use the JUnit assertions in a regular app class rather than a test class?
Delete <scope>test</scope>
When a Maven dependency carries a scope element with a value of test, that means you cannot use that library outside of your test-specific source package/folder.
If you are trying to call JUnit from code in your example project’s src/main/java/… folder hierarchy, you will see that error. If you call JUnit from src/test/java…, you will see success.
To enable JUnit in the src/main/java/… folder hierarchy, delete the scope element in your POM dependency. So this:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
<scope>test</scope>
</dependency>
…becomes this:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
</dependency>
By the way, note that as of 5.4.0 of JUnit, we can specify the new and very convenient single Maven artifact of junit-jupiter which in turn will supply 8 libraries to your project.

JUnit and WebDriver by IntelliJ IDEA

Im working in IntelliJ and need to add dependency's to Selenum WebDriver and Junit.
I already added the jars (as mentioned in all possible tutorial) to my Project lib.
I can also see them in the project view - Selenium-java-2.39.0.jar, Selenium-java-2.39.0.srcs.jar, Selenium-server-standalone-2.39.0.jar AND junit-4.11.jar
Nevertheless, my project can not recognized this items (for example
import org.openqa.selenium.;
import static org.junit.Assert.;
Any ideas?
I would recommend investing some time learning about some dependency management solutions. Here are my top two selections:
Maven
Ivy
If using maven, you'd have a pom.xml in your project and you'd have something like:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-ie-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium_version}</version>
</dependency>
...
</dependencies>
Ivy is very similar, but i won't get into it. If you need a project to get you started, you can check out this project (download here) which is used by Major League Gaming for their selenium framework
I agree, you should invest in a dependency management solution, but if you are not forced to use maven, try gradle.
It is way lighter and flexible...
In that case, my dependencies are resume to 1 line:
compile "org.gebish:geb-spock:0.9.2", "org.seleniumhq.selenium:selenium-firefox-driver:2.39.0", "org.seleniumhq.selenium:selenium-support:2.39.0"
I agree, I could add a second line with a property for the selenium version.
Gradle is really well supported by intellij Idea.
enjoy

Using Cucumber with IntelliJ

Does anyone knows why 'Cucumber Java' does not appear in "Edit Configurations -> Defaults -> ???? even though my pom file as downloaded the dependency i.e. cucumber-java (1.1.5)
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.38.0</version>
</dependency>
</dependencies>
Pom.xml file is used to install all the necessary plugins i.e. cucumber for java plugin
Make sure you have installed and enabled the Cucumber for Java plugin from the JetBrains plugin repository.
Look in the File -> Settings...
And you cannot install plugins into IDEA via Maven.
Just to add on top of the Answer by- Eugene.
While searching for Cucumber plugin, under File>Settings>plugins of Intellij you might not be able to see any Plugin available for cucumber and this is very weird issue for IntelliJ on windows.. troubled me for Hours..
But to solve it- we just have to click on 'Search in repositories' link as displayed on search panel. This will show all available stuff and you can select Cucumber for Java(or whatever).

How to make IntelliJ understand annotations

I have recently switched from using Eclipse to IntelliJ, and am preferring the experience.
However, the IDE is not understanding any of the Annotations. I am using Spring #Autowired annotation as well as some of the Spring-WS annotations and the IDE is telling me that they are unresolved.
When the project is built using Maven, it builds fine, and the Annotations are recognised in Eclipse.
Im sure this is a simple setup thing, but cannot find any information on how to set it up.
As Peter said, when correctly importing the Maven project the dependencies should be correctly recognized. The IntelliJ manual has a section on how to import a Maven project.
For the record, in our project pom, we have the following dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
The former two have been present already before implementing a web service, so they may not be required strictly for web services.