No tasks available when executing JUnit runner class

Intellij IdeaJunitCucumberCucumber JunitTest Runner

Intellij Idea Problem Overview


I am trying to run Cucumber feature files in IntelliJ.

Cucumber Options is pointing to the right folder, but I get the "No tasks available" notification when trying to execute the JUnit runner class.

What am I doing wrong?

enter image description here

Here is my build.gradle:

plugins {
    id 'java'
}

sourceCompatibility = 1.8

apply plugin: 'java'

repositories {
    mavenCentral()
}

compileJava.options.encoding = "UTF-8"

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile 'io.cucumber:cucumber-java:4.7.1'
    compile 'org.seleniumhq.selenium:selenium-server:2.44.0'
    testImplementation 'io.cucumber:cucumber-java:4.7.1'
    compile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
    compile group: 'io.cucumber', name: 'cucumber-java', version: '4.7.1'
    compile group: 'io.cucumber', name: 'cucumber-junit', version: '4.7.1'
    compile group: 'io.cucumber', name: 'cucumber-core', version: '4.7.1'
    compile group: 'net.masterthought', name: 'cucumber-reporting', version: '3.20.0'
    compile group: 'io.cucumber', name: 'gherkin', version: '5.1.0'
    compile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
    compile group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.6.0'
}

Intellij Idea Solutions


Solution 1 - Intellij Idea

Ok, none of the proposed solutions worked, but I finally figured it out.

Went to Settings > Build, Execution, Deployment > Build Tools > Gradle and changed Run tests using: from Gradle (Default) to IntelliJ IDEA.

enter image description here

Note: found the solution here.

Solution 2 - Intellij Idea

When I had this problem ("No tasks available" message when trying to run a test), what worked for me was to simply re-import the project from the Gradle view.

Right-click on project in Gradle view and select Reimport Gradle Project.

Solution 3 - Intellij Idea

I was facing the same issue. When using gradle make sure your project structure is correct. Your tests should be in src>test>java

This resolved the issue for me.

Java Test Structure

Solution 4 - Intellij Idea

"No tasks available" – I got this message when trying to run Spock test.

The reason was I did not have gradle plugins configured properly:

plugins {
    id 'java-library'
    id 'groovy' // this one is also necessary
}

Make sure you have 'groovy' plugin enabled, then re-import your project.

Solution 5 - Intellij Idea

I had the same problem. When I used the full package name in glue it worked, this is mine:

    ...
    features = "src/test/resources/features",
	glue = {"test.java.stepdefinitions"},
    ...

Solution 6 - Intellij Idea

I faced the same issue when I was trying to run the JUnit tests in my Gradle project. the solution worked in my case.

enter image description here

Solution 7 - Intellij Idea

I also faced a similar issue, In my case, it was because I forget to use the "public" access modifier while defining test class, and apparent with Junit 4, all test classes should be public.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMate MršeView Question on Stackoverflow
Solution 1 - Intellij IdeaMate MršeView Answer on Stackoverflow
Solution 2 - Intellij Ideauser2846469View Answer on Stackoverflow
Solution 3 - Intellij IdeaKashyap BariView Answer on Stackoverflow
Solution 4 - Intellij IdeaYaroslav StavnichiyView Answer on Stackoverflow
Solution 5 - Intellij Ideaou_ryperdView Answer on Stackoverflow
Solution 6 - Intellij Ideasophia guoView Answer on Stackoverflow
Solution 7 - Intellij IdeaArpit AgarwalView Answer on Stackoverflow