score:0

eclipse is not expecting anything else to be mucking with the class files. it assumes that if you haven't editted the file in eclipse it hasn't changed and doesn't need compiling. i think the issue stems from eclipse and maven sharing an output directory. i've often seen this if my mvn build fails, it will have deleted the class files as part of the clean but not compiled new ones. i think the best solution would be to have seperate build dirs for mvn and eclipse, but i've never look into this.

score:0

my problem wasn't the junit plugin but rather the configuration in my pom.xml.

after reviewing all the answers to this question, @gulats's answer implied to me that i should try setting a testoutputdirectory in my maven-compiler-plugin section, and that did the trick:

<plugin>
  <groupid>org.apache.maven.plugins</groupid>
  <artifactid>maven-compiler-plugin</artifactid>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <testoutputdir>${basedir}/target/test-classes</testoutputdir>
  </configuration>
</plugin>

score:1

i faced same issue. tried above suggestions of configuring output folder & maven>update project but neither worked. finally changed my testoutputdirectory to "build/classes" as well and now unit tests are getting picked up and executed.

finally found the reason for the issue. in my pom we had also configured maven compiler plugin as below

        <plugin>
            <groupid>org.apache.maven.plugins</groupid>
            <artifactid>maven-compiler-plugin</artifactid>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <outputdirectory>build/classes</outputdirectory>
            </configuration>
       </plugin>

outputdirectory configuration is not needed and was the cause of above issue. after removing this tag, junits are getting compiled to build>testclasses folder and are being run during maven build as well. yippee :)

score:1

please check "testsourcedirectory" path which can be configured in your pom.xml. and then, add the folder (configured in "testsourcedirectory" path) to the eclipse build path.

please find the sample "testsourcedirectory" in pom.xml below:

<build>
    <testsourcedirectory>src/test/java</testsourcedirectory>
    <plugins>
     <plugin>
        <artifactid>maven-compiler-plugin</artifactid>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>      
    </plugins>
  </build>

score:1

make sure that is there any exclamation mark on your project icon! in my case, i ignored that there is a exclamation point like: exclamation point on project icon

open the "markers" perspective, then troubleshoot the problems according to the tips. what the "markers" perspective show

the junit test classes can be execute successfully after i called "mvn clean test" because they are not refer the unreadable jar which be warned in "markers" perspective.therefor, it's easily to ignore it..

score:1

for someone working on java-scala mix project, this is something to note. even after doing the configuration in the manner shown below,

<build>
    <testoutputdirectory>${basedir}/target/test-classes</testoutputdirectory>
    <plugins>
    ...
        <plugin>
            <groupid>net.alchim31.maven</groupid>
            <artifactid>scala-maven-plugin</artifactid>
            <version>3.3.2</version>
            <configuration>
                <testsourcedir>${basedir}/src/test/scala</testsourcedir>
                <testoutputdir>${basedir}/target/test-classes</testoutputdir>
            </configuration>
         </plugin>
    </plugins>
</build>

and doing a maven > update project, eclipse honours the output directory of the src/test/java folder in the project, however, not for the src/test/scala folder. (you can figure this out by right-clicking on the specific source folder and choosing build path > configure output folder... which should display the location as specified in the pom for the former case, however, not for the later case.

this is already a known bug for using scala with m2e as mentioned here: http://scala-ide.org/docs/tutorials/m2eclipse/

warning

as of march 2013, a bug causes both src/main/scala and src/test/scala to use the default output folder (target/classes). this may be confusing >when building tests, since their class files will not end in target/test-classes, as they would when building on the command line. you can work around this by manually changing the output folder for src/test/scala.

score:2

and another point: junit test classes should be in src/test/java, not src/main/java, otherwise they aren't detected correctly by maven as test classes and they would be included in the packaged jar and not in the test jar.

score:3

the most likely explanations for the problem you are facing is that the output folder of src/test/java is not correctly configured.

instead of fixing this configuration manually, you can have m2eclipse fix this for you: just right-click on the project and choose maven > update project.

score:6

in addition to the answer below

  1. right click the src/test/java folder
  2. select build path -> configure output folder
  3. enter target/test-classes, click ok

you should check to ensure that your builder is setup correctly by right clicking your project and going to properties -> builder. if you see that your builder is missing, you need to install one. in my case, the maven project had an aspectj dependency and when i used the maven eclipse plugin to build my eclipse project, it was looking for an aspectj builder by default. i installed the aspectj development tools and it solved the problem.

hope this helps!

score:89

i had the same problem with sts eclipse (spring development variant), m2e and junit. the solution was to set the output folder for src/test/java to target/test-classes:

  1. right click the src/test/java folder in the package explorer
  2. select build path -> configure output folder
  3. enter target/test-classes, click ok

now the changes in test classes are compiled correctly and you should be able to run junit tests in eclipse.

the problem is that eclipse compiles the unit tests to the default output folder target/classes while junit plugin correctly tries to run them from test-classes.

there are a few duplicates to this question:


Related Query

More Query from same tag