Question

I am completely new to jbehave and even automated testing. I read a tutorial online and tried following the steps.

I am trying to run this application in eclipse IDE.

I made a Math.story file which contains the tests:

Scenario: 2 squared
Given a variable x with value 2
When I multiply x by 2 
Then x should equal 4

In a .java file called ExampleSteps.java, the steps are written:

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.steps.Steps;

public class ExampleSteps extends Steps {
    int x;

    @Given("a variable x with value $value")
    public void givenXValue(@Named("value") int value) {
        x = value;
    }

    @When("I multiply x by $value")
    public void whenImultiplyXBy(@Named("value") int value) {
        x = x * value;
    }

    @Then("x should equal $value")
    public void thenXshouldBe(@Named("value") int value) {
        if (value != x)
            throw new RuntimeException("x is " + x + ", but should be " + value);
    }
}

I created another class SimpleJbehave which has the main method: import java.util.Arrays; import java.util.List;

import org.jbehave.core.embedder.Embedder;

public class SimpleJBehave {

    private static Embedder embedder = new Embedder();
    private static List<String> storyPaths = Arrays
            .asList("Math.story");

    public static void main(String[] args) {
        embedder.candidateSteps().add(new ExampleSteps());
        embedder.runStoriesAsPaths(storyPaths);

    }
}

When I run this code, I get the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/Transformer
    at org.jbehave.core.configuration.Configuration.<init>(Configuration.java:112)
    at org.jbehave.core.configuration.MostUsefulConfiguration.<init>(MostUsefulConfiguration.java:49)
    at org.jbehave.core.embedder.Embedder.<init>(Embedder.java:30)
    at org.jbehave.core.embedder.Embedder.<init>(Embedder.java:37)
    at SimpleJBehave.<clinit>(SimpleJBehave.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

As I am a novice, I have not been able to understand what exactly the problem is.

It will be really nice if someone could tell me what I should do to get this code working. Is my approach wrong?

Thank you very much in advance.

No correct solution

OTHER TIPS

It looks like you don't have org.apache.commons.collections.Transformer on your classpath. It looks like this class is available in the apache-commons-transformer library here: http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html

Download the jar and add it to your classpath. It might work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top