7

I've got a simple-enough project that I'm trying to test with JBehave core, and doing things in a maven-kosher fashion (that is production under src/main, test under src/test, integration testing stuff under an added path of src/it/{java,resources}, and test dependencies scoped with test). Getting this all running together seems rather harder than it should be.

My case is a little different because my code is in src/it/java, and resources in src/it/resources. Having configured those in maven, Eclipse runs the stories just fine - the problem is with Maven.

Currently my problem is that it doesn't see mockito (or other test dependencies) when running (mvn -X). Even editing a working example and adding a test dependency doesn't include it.

I've been able to bodge it into working by sticking my test dependencies within the plugin xml blob, but obviously I don't want to repeat myself like that.

The relevant parts of the build file (without the manually specified dependency hack) are:

<testResources>
    <testResource>
        <directory>src/test/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*</include>
        </includes>
    </testResource>
    <testResource>
        <directory>src/it/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*</include>
        </includes>
    </testResource>
</testResources>

...

  <plugin>
    <groupId>org.jbehave</groupId>
    <artifactId>jbehave-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>embeddable-stories</id>
        <phase>integration-test</phase>
        <configuration>
          <includes>
            <include>**/*Story.java</include>
          </includes>
          <ignoreFailureInStories>false</ignoreFailureInStories>
          <ignoreFailureInView>false</ignoreFailureInView>
          <scope>test</scope>
          <testSourceDirectory>src/it/java</testSourceDirectory>
        </configuration>
        <goals>
          <goal>run-stories-as-embeddables</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Ideas?

Dave LeBlanc
  • 346
  • 4
  • 12

2 Answers2

4

The plugin has property scope which defaults to compile, I suppose you should to change it to test. Consult with the documentation.

Also, here is good point why compile is by default.

kan
  • 28,279
  • 7
  • 71
  • 101
  • I like the point about keeping it in src/main. I tried `test` but Maven still seemed to ignore it. Does that `` element belong in the `` element? It doesn't seem to make Maven make jBehave look in the right place. – Michael Osofsky Dec 23 '14 at 00:58
  • @MichaelOsofsky This `` is a part of plugin configuration too. – kan Dec 23 '14 at 10:21
  • Thanks @kan, it looks like `` belongs in the `` element of ``. Thank you! – Michael Osofsky Dec 23 '14 at 19:02
  • I ran into one issue with keeping JBehave in src/main instead of src/test. See http://stackoverflow.com/questions/27629791/adding-runwith-for-jbehave-junit-runner-breaks-jbehave-build-using-maven/27629792#27629792 – Michael Osofsky Dec 24 '14 at 00:04
2

According to jbehave maven plugin documentation,

When using the JBehave Maven Plugin, and depending on the rest of your POM configuration, you may need to add Apache log4j as Plugin Dependency (as opposed to the Project Dependency) if you find that it's not able to load its classes

Could you be facing the same issue?

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • Well, this is what I meant when I said "sticking my test dependencies within the plugin xml blob", but I don't think it's a good solution - from the looks of it, I need to duplicate all my test dependencies in there. Perhaps I'll ask on the mailing list and report any findings back here. – Dave LeBlanc May 07 '11 at 05:53
  • 1
    @Dave LeBlanc. According to the doc, *only* log4j was required. I guess it is more than that in your case – Raghuram May 07 '11 at 12:40
  • @DaveLeBlanc did you get an answer? – Robert Watkins Jun 20 '12 at 02:30