执行JUnit运行器类时没有可用的任务

Mat*_*rše 7 junit intellij-idea cucumber cucumber-junit

我正在尝试在IntelliJ中运行黄瓜功能文件。

Cucumber Options指向正确的文件夹,但是在尝试执行JUnit运行器类时收到“无可用任务”通知。

我究竟做错了什么?

在此处输入图片说明

这是我的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'
}

Run Code Online (Sandbox Code Playgroud)

Mat*_*rše 108

好吧,提出的解决方案都没有奏效,但我终于想通了。

Settings > Build, Execution, Deployment > Build Tools > Gradle,改变了Run tests using:Gradle (Default)IntelliJ IDEA

在此处输入图片说明

注意:在这里找到了解决方案。


use*_*469 45

当我遇到这个问题(尝试运行测试时出现“无可用任务”消息)时,对我有用的是简单地从 Gradle 视图重新导入项目。

在 Gradle 视图中右键单击项目并选择“重新导入 Gradle 项目”。


小智 16

我面临着同样的问题。使用 gradle 时请确保您的项目结构正确。您的测试应该位于src>test>java中

这为我解决了这个问题。

Java测试结构


Yar*_*hiy 8

“没有可用的任务” – 我在尝试运行 Spock 测试时收到此消息。

原因是我没有正确配置 gradle 插件:

plugins {
    id 'java-library'
    id 'groovy' // this one is also necessary
}
Run Code Online (Sandbox Code Playgroud)

确保您启用了“groovy”插件,然后重新导入您的项目。