无法使用Serenity Framewrok使用Gradle执行Jbehave

时间:2015-10-06 04:28:58

标签: gradle junit4 jbehave

我正在使用Serenity - JBehave框架。创建示例脚本后,我可以从eClipse执行Junit runner类,但是当我尝试从命令提示符执行以下任何命令时,它会给我错误。

$gradle clean test aggregate
$gradle clean test
$gradle clean build

错误信息在所有情况下都相同,如下所示:

org.gradle.TestRunnerClass > initializationError FAILED
    java.lang.RuntimeException
        Caused by: java.lang.RuntimeException
            Caused by: java.lang.IllegalArgumentException
                Caused by: java.lang.ClassNotFoundException

1 test completed, 1 failed
:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///C:/$ /build/reports/tests/index.html

以下是详细信息: Test Runner类:

package org.gradle;

import net.serenitybdd.jbehave.SerenityStories;

public class TestRunnerClass extends SerenityStories{}

Sample Step Definition类:

package org.gradle.stepDef;

import net.thucydides.core.annotations.Step;
import net.thucydides.core.annotations.Steps;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

public class StepDefSticky {
    @Given("User is on Sticky note home page")
    public void givenUserIsOnStickyNoteHomePage() {
      System.out.println("I am in Given");
    }

    @When("User clicks on Add Note button")
    public void whenUserClicksOnAddNoteButton() {
        System.out.println("I am in When");
    }

    @Then("Sticky note pop up should get open")
    public void thenStickyNotePopUpShouldGetOpen() {
        System.out.println("I am in Then");
    }
}

请仔细查看包装结构。

以下是我正在使用的build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'net.serenity-bdd.aggregator'
apply plugin: 'com.jfrog.bintray'

sourceCompatibility = 1.8
version = '1.0'
def poiVersion = "3.10.1"

repositories {
    maven { url "repoUrl" }
}

buildscript {
    repositories {
        maven { url "repoURL" }
    }
    dependencies {
        classpath("net.serenity-bdd:serenity-gradle-plugin:1.0.47")
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.6'
        classpath 'org.ajoberstar:gradle-git:0.12.0'
    }
}

ext {
    bintrayBaseUrl = 'https://api.bintray.com/maven'
    bintrayRepository = 'maven'
    bintrayPackage = 'serenity-cucumber'
    projectDescription = 'Serenity Cucumber integration'
    if (!project.hasProperty("bintrayUsername")) {
        bintrayUsername = 'wakaleo'
    }
    if (!project.hasProperty("bintrayApiKey")) {
        bintrayApiKey = ''
    }
    serenityCoreVersion = '1.0.47'
    cucumberJVMVersion = '1.2.2'
}

dependencies {

    testCompile('junit:junit:4.11')
    testCompile('org.assertj:assertj-core:1.7.0')
    testCompile('org.slf4j:slf4j-simple:1.7.7')


    //JBehave jar files
    testCompile 'net.serenity-bdd:core:1.0.47'
    testCompile 'net.serenity-bdd:serenity-jbehave:1.0.21'
    testCompile 'net.serenity-bdd:serenity-junit:1.0.47'

    // Apache POI plugin for excel read
    compile "org.apache.poi:poi:${poiVersion}"
    compile "org.apache.poi:poi-ooxml:${poiVersion}"
    compile "org.apache.poi:ooxml-schemas:1.1"
}


   gradle.startParameter.continueOnFailure = true

uploadArchives {
    repositories { flatDir { dirs 'repos' } }
}

task wrapper(type: Wrapper) { gradleVersion = '2.3' }

我已将.story文件存储在src / test / resources包下。

请帮我理解我犯错误的地方。感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在build.gradle文件中启用标准输出和标准错误:

test {
    testLogging {
        showStandardStreams = true
    }
}

为了确保所有故事都能运行,请添加一个TestSuite类:

@RunWith(Suite.class)
@SuiteClasses({ Story1.class, Story2.class})
public class TestSuite { }

注意:Story1& Story2是测试跑步者的名字,用于匹配名为Story1.story&的JBehave Gherkin文件。 Story2.story&步骤文件名称Story1Steps.java&根据Serenity命名惯例,Story2Steps.java。