2015-04-10 15 views
5

Durante la creazione del mio progetto con Maven utilizzando JUnit-Tests con surefire e Cobertura per ottenere la copertura di test, normalmente, tutto ha funzionato correttamente. Ma quando recentemente ho aggiunto una deroga che potrebbe essere gettato (e è escluso) da parte di alcuni test, Maven mi ha sempre detto:Cobertura causa ClassNotFoundException

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project backend-server: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: There was an error in the forked process 
[ERROR] java.lang.NoClassDefFoundError: de/unileipzig/irpsim/backend/simulation/TimerowTooShortException 
[ERROR] at java.lang.Class.getDeclaredMethods0(Native Method) 
[ERROR] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) 
[ERROR] at java.lang.Class.privateGetMethodRecursive(Class.java:3048) 
[ERROR] at java.lang.Class.getMethod0(Class.java:3018) 
[ERROR] at java.lang.Class.getMethod(Class.java:1784) 
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(ReflectionUtils.java:57) 
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(JUnit3TestChecker.java:64) 
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(JUnit3TestChecker.java:59) 
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(JUnit3TestChecker.java:54) 
[ERROR] at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept(JUnit4TestChecker.java:52) 
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:97) 
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:222) 
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:107) 
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) 
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) 
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) 
[ERROR] Caused by: java.lang.ClassNotFoundException: de.unileipzig.irpsim.backend.simulation.TimerowTooShortException 
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
[ERROR] ... 16 more 
[ERROR] -> [Help 1] 

una corsa con -X o cose del genere, purtroppo, non ha aiutato, e anche guardando http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html o Intermittent NoClassDefFoundError when running a maven/surefire build in jenkins non hanno offerto alcun suggerimento utile per questo problema.

mio infallibile-plugin è definito come segue:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.18.1</version> 
    <configuration> 
     <forkedProcessTimeoutInSeconds>900</forkedProcessTimeoutInSeconds> 
     <argLine>-Djava.library.path=${nativelib.directory}</argLine> 
     <excludes> 
      <exclude>**/DatabaseTest.java</exclude> 
     </excludes> 
    </configuration> 
</plugin> 

Quando disattivazione della biforcazione, tutto comincia a lavorare bene, ma i nativi-libs non sono inclusi, quindi questo non è un'opzione. Inoltre, quando escludo tutti i test che utilizzano lo TimerowTooShortException, tutto funziona correttamente.

Dopo alcuni tentativi, ho scoperto che la cobertura, anche quando il test viene eseguito con -Dcobertura.skip=true, sta causando il problema. Cobertura è stata definita nei plugin come segue:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>cobertura-maven-plugin</artifactId> 
    <version>2.6</version> 
    <configuration> 
     <formats> 
      <format>xml</format> 
     </formats> 
    </configuration> 
    <dependencies> 
     <dependency> 
      <groupId>org.ow2.asm</groupId> 
      <artifactId>asm</artifactId> 
      <version>5.0.3</version> 
     </dependency> 
    </dependencies> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>cobertura</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

purtroppo non ho potuto trovare tutte le informazioni su questo problema specifico quando si utilizza infallibile e cobertura insieme con un'eccezione prevista. Qualcuno sa perché questo accade quando si usa la cobertura? E c'è una soluzione per questo?

risposta

0

ho avuto lo stesso errore, ma l'aggiunta di

`<testFailureIgnore>false</testFailureIgnore>` 

risolvere il problema. Quindi la prossima configurazione dovrebbe risolvere il problema.

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.18.1</version> 
      <configuration> 
       <skipTests>${skipTests}</skipTests> 
       <testFailureIgnore>false</testFailureIgnore> 
       <includes> 
       <include>**/*.java</include> 
       </includes> 
      </configuration> 
     </plugin> 
3

Ho riscontrato un errore simile con un progetto multimodule. Ogni volta che ho aggiunto il -Dcobertura.skip=true ho ottenuto le eccezioni NoClassDefFound e ClassNotFound.

Sfortunatamente non sono riuscito a capire perché. La mia ipotesi è che non tutti gli obiettivi di cobertura prendano il parametro.

Tuttavia, ho "risolto" il problema utilizzando i profili. Cioè, ho spostato il plugin di cobertura dalla configurazione di build di default al profilo di cobertura.

<profiles> 
    <profile> 
     <id>cobertura-run</id> 
     <properties> 
      <maven.test.skip>false</maven.test.skip> 
     </properties> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>cobertura-maven-plugin</artifactId> 
        <version>2.7</version> 
        <configuration> 
         <formats> 
          <format>xml</format> 
         </formats> 
        </configuration> 
        <executions> 
         <execution> 
          <phase>package</phase> 
          <goals> 
           <goal>cobertura</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

Ogni volta che voglio cobertura a correre, io uso -P cobertura-run invece di disabilitare o abilitare cobertura a riga di comando.

Problemi correlati