maven - 我如何在Groovy项目中使用 cucumber 定义缺少的步骤?

标签 maven grails groovy cucumber cucumber-jvm

我有一个项目在groovy中(不是Maven结构)如何,当我查看功能时

Feature: API Authentication Functionality

@Api @General
Scenario: I cannot log in to the API with bad credentials
Given the following users are defined:
    | USER_EMAIL               | RAW_PASSWORD     |
  | test@test.reachforce.com | YesGoodPassword! |
 And I use the username 'test@test.reachforce.com'
  And I use the password 'UhOhWrongWord!'
  When I log in to the API
  Then the response is forbidden

 @Api @General
  Scenario: I log in to the API
    Given the following users are defined:
     | USER_EMAIL               | RAW_PASSWORD     |
      | test@test.reachforce.com | YesGoodPassword! |
   And I use the username 'test@test.reachforce.com'
   And I use the password 'YesGoodPassword!'
   When I log in to the API
   Then the response is valid
   And the response includes a token


但是在步骤中会出现此警告:

step the following users are defined does not have a matching glue code



步骤结构类似于:AuthenticationSteps.groovy

而当我运行它给我这个错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:68)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:65)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:65)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:162)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    at com.reachforce.tools.db.DataSourceFactory.<init>(DataSourceFactory.groovy:12)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:239)
    at com.reachforce.config.ValidationConfig.<init>(ValidationConfig.groovy:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:436)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:680)
    at cucumber.runtime.groovy.GroovyBackend.parse(GroovyBackend.java:115)
    at cucumber.runtime.groovy.GroovyBackend.loadGlue(GroovyBackend.java:76)
    at cucumber.runtime.Runtime.<init>(Runtime.java:91)
    at cucumber.runtime.Runtime.<init>(Runtime.java:69)
    at cucumber.runtime.Runtime.<init>(Runtime.java:65)
    at cucumber.api.cli.Main.run(Main.java:35)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.io.FileNotFoundException: \etc\validation\validation.properties (El sistema no puede encontrar la ruta especificada)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(ConstructorSite.java:45)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
    at com.reachforce.config.ValidationEnvironment.<clinit>(ValidationEnvironment.groovy:10)
... 36 more

有什么帮助吗?

最佳答案

看起来您的Cucumber插件找不到步骤定义类。

  • 在您的构建文件中,如果您的文件夹结构与插件期望的不同,则需要将Cucumber指向功能和步骤定义的位置。

  • 尝试看一下使用Groovy步骤定义运行Cucumber的示例:
    Cucumber-jvm-groovy-example

    关于maven - 我如何在Groovy项目中使用 cucumber 定义缺少的步骤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407816/

    相关文章:

    maven - OSSRH 版本未复制到 Maven Central

    java - 仅当 JNDI 资源可用时才在 JBoss 上部署 WAR 文件

    xml - 将xml更改为数组的更快方法(可以伸缩)

    java - Grails:events.PatchedDefaultFlushEventListener - 无法将数据库状态与 session org.hibernate.StaleObjectStateException 同步

    groovy - 斜线有什么好处?

    multithreading - 任务数量未知的多线程

    file - 如何在命令行中为 maven 发布插件设置排除列表?

    java - MockClassLoader无法访问jdk/internal/reflect父类(super class)jdk.internal.reflect.MagicAccessorImpl

    grails - 如何自定义grails字段插件

    ruby-on-rails-3 - 在 SOA 架构中使用 SPDY