2

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.

Lavanya Mohan
  • 1,496
  • 7
  • 28
  • 39

1 Answers1

1

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.

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • I added apache-collections-commons-collections-3.1.jar, freemarker-2.3.6.jar, jbehave-core-3.0.2.jar, org.apache.commons.io.jar and org.apache.commons.lang.jar to the path. But now, I get Failed to generate stories view in outputDirectory. It is caused by org.jbehave.core.reporters.FreemarkerViewGenerator$ViewGenerationFailedForTemplate. I am not sure how to deal with this? Is something wrong with the .story file that I created? Because it says, "no step is matching". I am really new to this and have no idea at all about what I should be doing. Thank you. – Lavanya Mohan Oct 18 '12 at 23:59
  • @Sathya: Did you find any solution to this problem, I am facing the same issue and I just started working on Jbehave, please let me know if there is a fix for this. Thanks in advance!! – Srivastava May 16 '17 at 11:46