我正在尝试在我的项目中实施BDD,并且我正在使用Jbehave,我指的是可用的在线资料,我创建了故事文件,Steps类和Runner类,如下所示,但我和#39;我得到一些奇怪的例外,我无法解决它。
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 Class,' 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类,我会得到
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
如果有人可以帮助我解决这个问题,那将会很棒。
答案 0 :(得分:0)
一般来说,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>