No tasks available when executing JUnit runner class
Asked Answered
H

8

70

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'
}

Hesperian answered 12/9, 2019 at 14:21 Comment(7)
Is it possible to share project example for investigation?Nosewheel
Not all of the project. What do you need?Allier
Could you create small project example demonstrating the issue, so dependencies/classpath/etc. could be checked?Nosewheel
@MateMrše Are you able to run the tests outside of IntelliJ, using the command line?Ssr
Please start with removing the 'cucumber-core' dependency (it is included in cucumber-java) and updating the cucumber-picocontainer to:` 'io.cucumber', name: 'cucumber-picocontainer', version: '4.7.1'` (making sure to use the same cucumber version for all your cucumber dependencies.Churr
Reimporting gradle projects fixed this for meDisapproval
@Rob I don't think this applies to this screenshot. I wanted to show the message that pops up. Besides, everything of interest already is typed into the question.Allier
H
132

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.

Hesperian answered 18/10, 2019 at 9:1 Comment(3)
What if I don't have a gradle option there? Only mavenDisapproval
I'm not sure about Maven, but I imagine it should be similar to this, just select Maven as build tool and then see what are the available options.Allier
this did not work for me. reimporting gradle project from gradle view workedDude
H
50

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.

Handball answered 13/12, 2019 at 8:33 Comment(2)
Note: 'Reimport All Gradle Projects' didn't work for me, at least in the version I tested it in. That's why I wrote instructions for re-importing the individual project.Handball
This worked for me, but it appears to be named Reload Gradle Project now.Currin
K
16

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

Killdeer answered 22/2, 2021 at 11:5 Comment(2)
Thanks, actually this solved the problem that took me hours strugggling.Marrs
it really help me a lot, thanksSwingle
H
8

"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.

Heman answered 15/5, 2020 at 17:19 Comment(1)
That was it, my Groovy tests are running, using only IntelliJ. Thanks a ton!Neonatal
E
3

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"},
    ...
Elusive answered 10/10, 2019 at 13:13 Comment(2)
where to make this change?Bunting
In @CucmberOptions. See question on top of the pageElusive
J
1

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.

Jerboa answered 20/10, 2021 at 11:39 Comment(2)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewOptical
@Rana BS, I ran into the exact same issue, and this solved it. Actually, I came to add the solution in case it didn't exist yet (funny how the same tests do run on other platforms).Lowercase
B
0

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

Beaulieu answered 14/7, 2021 at 22:19 Comment(0)
B
0

In the Android Studio, open the Gradle panel and right click on your project name, then click on Reload Gradle Project

enter image description here

Bison answered 6/1, 2023 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.