无法调用Cucumber JVM中使用@Before钩子注释的方法

时间:2016-06-24 14:22:51

标签: cucumber cucumber-jvm cucumber-java

我正在使用@Before钩子来获取Step中的Scenario。代码段如下。

import cucumber.api.java.Before;

private Scenario scenario     
@Before
      public void beforeScenario(Scenario scenario){
            this.scenario = scenario;

    }

现在执行步骤文件时,我收到以下错误

Cucumber.runtime.CucumberException: Error creating bean with name 'com.steps.TestSteps': Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
        at cucumber.runtime.java.spring.SpringFactory.getInstance(SpringFactory.java:182)
        at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60)
        at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:223)
        at cucumber.runtime.Runtime.runHooks(Runtime.java:211)
        at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:201)
        at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:40)
        at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
        at cucumber.runtime.Runtime.run(Runtime.java:121)
        at cucumber.api.cli.Main.run(Main.java:36)
        at cucumber.api.cli.Main.main(Main.java:18)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.steps.TestSteps': Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1101)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:342)
        at cucumber.runtime.java.spring.GlueCodeScope.get(GlueCodeScope.java:15)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:217)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:350)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
        at cucumber.runtime.java.spring.SpringFactory.getInstance(SpringFactory.java:180)
        ... 9 more

任何人都可以帮忙吗?

0 个答案:

没有答案