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

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • Is it possible to share project example for investigation? – y.bedrov Sep 12 '19 at 14:54
  • Not all of the project. What do you need? – Mate Mrše Sep 13 '19 at 11:12
  • Could you create small project example demonstrating the issue, so dependencies/classpath/etc. could be checked? – y.bedrov Sep 13 '19 at 11:38
  • @MateMrše Are you able to run the tests outside of IntelliJ, using the command line? – Rozart Oct 07 '19 at 11:33
  • 1
    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. – Marit Oct 09 '19 at 10:54
  • Reimporting gradle projects fixed this for me – Janac Meena May 22 '20 at 02:47
  • **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob Feb 22 '21 at 11:29
  • @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. – Mate Mrše Feb 22 '21 at 11:45

8 Answers8

131

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.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
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.

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
user2846469
  • 2,072
  • 3
  • 18
  • 32
  • 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. – user2846469 May 07 '20 at 08:49
  • 1
    This worked for me, but it appears to be named `Reload Gradle Project` now. – Adam Johns Dec 16 '22 at 19:47
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

Sunny Kumar Aditya
  • 2,806
  • 4
  • 26
  • 38
Kashyap Bari
  • 191
  • 1
  • 3
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.

Yaroslav Stavnichiy
  • 20,738
  • 6
  • 52
  • 55
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"},
    ...
ou_ryperd
  • 2,037
  • 2
  • 18
  • 23
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.

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30128549) – Rana Oct 20 '21 at 13:02
  • @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). – Maarten Bodewes Aug 29 '22 at 12:49
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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
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

Babak Karchini
  • 155
  • 1
  • 8