0

Our project has the following structure:

├─ A
   ├─ A-A
   ├─ A-B
   ├─ A-C
   ├─ A-D
   ├─ A-E
   ├─ A-F
   ├─ A-G

The relevant JUnit tests are located in A-A. Before we were using Maven, we had to adapt the run configuration (set the working directory in the arguments tab to A-B which starts the application) in Eclipse in order to launch all tests without errors.

Now we get a NoClassDefFoundError from a class located in A-A when we try to run the tests, no matter if we do that in Eclipse (Run As > JUnit Test) or with Maven (mvn test). I think this is different to similar issues on Stack Overflow because our tests aren't working at all.

My guess is that we have a bad configured POM and Surefire can't find all class files or something like that. Is there a way to configure the plugin the way we did it with the run configuration before? Or is this error caused by something else (like M2Eclipse)?

EDIT: The internal structure of project A-A is as follows (ClassCausingError extends a class from a Maven dependency):

├─ A-A
   ├─ src/main/java
       ├─ foo/bar/ClassCausingError.java
   ├─ src/main/resources
   ├─ src/test/java
       ├─ foo/bar/ClassCausingErrorTest.java
   ├─ target
   ├─ pom.xml
Community
  • 1
  • 1
beatngu13
  • 7,201
  • 6
  • 37
  • 66
  • I doubt there's enough information in your question to answer it, at the moment. Just to be clear though, you have a test in A-A that throws a NoClassDefFoundError for another class in A-A? – Duncan Jones Feb 17 '15 at 10:38
  • First are we talking about unit tests or integration tests? Furthermore you should be aware of that unit tests are limited to the given module. – khmarbaise Feb 17 '15 at 10:42
  • @Duncan Yes, there's a test in A-A that throws the error for a class in A-A (which I absolutely don't understand). – beatngu13 Feb 17 '15 at 10:50
  • 1
    @beatngu13 Can you edit your question to include the path to the test class and the path to the class that cannot be found? See also [this answer](http://stackoverflow.com/a/5756989/474189) which explains why NoClassDefFoundError is different to a ClassNotFoundException. – Duncan Jones Feb 17 '15 at 10:53
  • @khmarbaise There are both, unit and integration tests. The integration tests depend on several classes and configuration files in different modules, that's why we had to adapt the run configuration before. – beatngu13 Feb 17 '15 at 10:53
  • You are run the tests from `A-A` project, other project (such as `A-B`) or from the aggregator (by the structure, I think `A` is aggregator, right?)? Did you try run `mvn clean test`? – Bruno Ribeiro Feb 17 '15 at 11:15
  • @BrunoCésar I should run the tests with **A-B** as working directory (that's what we did before Maven and it worked, this is also the project which invokes the application launcher). But I also tried doing this from **A**, **A-A** and mvn clean test without success. – beatngu13 Feb 17 '15 at 11:28
  • 1
    @beatngu13 I think you need to work on a minimal example for us. Your example paths seem absolutely fine, so there should be no reason `ClassCausingErrorTest` can't find `ClassCausingError`. So start stripping away files and POM statements until you've got something minimal to share in your question. Until you've done that, i doubt we can help you. – Duncan Jones Feb 17 '15 at 14:09

1 Answers1

1

Setting the base directory in the main tab of the Maven build run configurations to A-B fixed the issue. This seems to have the same effect as setting the working directory for JUnit previously. In addition I edited the POM to make the tests run from the command line:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <configuration>
        <workingDirectory>A-B</workingDirectory>
    </configuration>
</plugin>
beatngu13
  • 7,201
  • 6
  • 37
  • 66