【问题标题】:Jbehave test Runner IssueJbehave 测试 Runner 问题
【发布时间】:2015-04-28 09:10:13
【问题描述】:

我正在尝试在我的项目中实现 BDD,并且我正在使用 Jbehave,我指的是可用的在线资料,我已经创建了故事文件、Steps 类和 Runner 类,如下所示,但我是遇到一些我无法解决的奇怪异常。

1) 故事文件,“Sample.story”

Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development

Scenario:  A scenario is a collection of executable steps of different type
Given I type Hello
When Hit Enter
Then It prints Hellows

2) 步骤定义文件,'SampleSteps.java'

package com.kar.features;

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

public class SampleSteps {

@Given("I type Hello")
public void TypeHello(){
    System.out.println("welcome to Cucumber");
}

@When ("Hit Enter")
public void SetBalanceToZero(){
    System.out.println("Inside the 'Enter' section");
}

@Then ("It prints Hellows")
public void addAmount(){
    System.out.println("I'm at the end");
}
}

3) Runner 类,“Sample.java”

package com.kar.features;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.junit.JUnitStory;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;

public class Sample extends JUnitStory {

@Override public Configuration configuration() {
    return new MostUsefulConfiguration();
}

@Override public InjectableStepsFactory stepsFactory() {
    return new InstanceStepsFactory(configuration(),
            new SampleSteps());
}
}

但是如果我使用 Junit 运行 Runner 类,我会得到 ​​p>

java.lang.NoClassDefFoundError: com/thoughtworks/paranamer/Paranamer
at org.jbehave.core.embedder.Embedder.<init>(Embedder.java:50)
at org.jbehave.core.embedder.Embedder.<init>(Embedder.java:60)
at org.jbehave.core.ConfigurableEmbedder.<init>    (ConfigurableEmbedder.java:40)
at org.jbehave.core.junit.JUnitStory.<init>(JUnitStory.java:16)
at com.kar.features.Sample.<init>(Sample.java:9)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.paranamer.Paranamer
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 27 more

如果有人能帮我解决这个问题,那就太好了。

【问题讨论】:

  • 我复制了你的代码和 .story,运行它没有失败。您使用什么版本的 JBehave?你用的是maven吗?我猜您的问题可能与某些缺少的依赖项有关。
  • 不,我没有使用 Maven,如果可能,请您分享 pom.xml 文件,以便我可以尝试使用 maven 运行?

标签: cucumber bdd jbehave


【解决方案1】:

一般来说,JBehave 对故事运行器使用匹配模式。它在类名中查找 Test。它可以像这样在 maven 中显式配置:

        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.11</version>
            <configuration>
                <includes>
                    <include>**/*Test.java</include>
                    <include>**/Test*.java</include>
                    <include>**/When*.java</include>
                    <include>**/*TestSuite.java</include>
                </includes>
                <argLine>-Xmx512m</argLine>
                <parallel>classes</parallel>
                <systemPropertyVariables>
                    <webdriver.driver>${webdriver.driver}</webdriver.driver>
                </systemPropertyVariables>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多