2016-03-24 5 views
4

in Eclipse Ich habe EcLEmma verwendet, um die Unit-Test-Code-Abdeckung zu sehen. das hat gut funktioniert. Deshalb habe ich versucht, das jacoco-Plugin für Maven zu verwenden, um den gleichen Bericht mit todsicheren Maven Build oder noch besser mit einem bestimmten Profil oder im Site-Zyklus zu sehen. Alle kläglich gescheitertmaven unit Testcode Abdeckung

Alle schlagen hier Lösungen nicht für mich arbeiten

was ist der beste Weg, um einen UniSt Test Code-Coverage-Bericht (mit todsicherem) zu bekommen? [Bearbeiten] mehr spefici, warum jacoco für mich im Stich gelassen .... da ich aufgrund fehlender Ausführungsdaten

vom pom in den Eigenschaften

<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file> 
    <jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file> 

alswas der Skipping JaCoCo Ausführung bekam im Build Abschnitt

 <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId>org.jacoco</groupId> 
            <artifactId>jacoco-maven-plugin</artifactId> 
            <versionRange>${jacoco.version}</versionRange> 
            <executions> 
             <!-- Prepares the property pointing to the JaCoCo runtime agent 
              which is passed as VM argument when Maven the Surefire plugin is executed. --> 
             <execution> 
              <id>pre-unit-test</id> 
              <goals> 
               <goal>prepare-agent</goal> 
              </goals> 
              <configuration> 
               <!-- Sets the path to the file which contains the execution 
                data. --> 
               <destFile>${jacoco.ut.execution.data.file}</destFile> 
               <!-- Sets the name of the property containing the settings for 
                JaCoCo runtime agent. --> 
               <propertyName>surefireArgLine</propertyName> 
              </configuration> 
             </execution> 
             <!-- Ensures that the code coverage report for unit tests is created 
              after unit tests have been run. --> 
             <execution> 
              <id>post-unit-test</id> 
              <phase>test</phase> 
              <goals> 
               <goal>report</goal> 
              </goals> 
              <configuration> 
               <!-- Sets the path to the file which contains the execution 
                data. --> 
               <dataFile>${jacoco.ut.execution.data.file}</dataFile> 
               <!-- Sets the output directory for the code coverage report. --> 
               <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> 
              </configuration> 
             </execution> 
             <!-- Prepares the property pointing to the JaCoCo runtime agent 
              which is passed as VM argument when Maven the Failsafe plugin is executed. --> 
             <execution> 
              <id>pre-integration-test</id> 
              <phase>pre-integration-test</phase> 
              <goals> 
               <goal>prepare-agent</goal> 
              </goals> 
              <configuration> 
               <!-- Sets the path to the file which contains the execution 
                data. --> 
               <destFile>${jacoco.it.execution.data.file}</destFile> 
               <!-- Sets the name of the property containing the settings for 
                JaCoCo runtime agent. --> 
               <propertyName>failsafeArgLine</propertyName> 
              </configuration> 
             </execution> 
             <!-- Ensures that the code coverage report for integration tests 
              after integration tests have been run. --> 
             <execution> 
              <id>post-integration-test</id> 
              <phase>post-integration-test</phase> 
              <goals> 
               <goal>report</goal> 
              </goals> 
              <configuration> 
               <!-- Sets the path to the file which contains the execution 
                data. --> 
               <dataFile>${jacoco.it.execution.data.file}</dataFile> 
               <!-- Sets the output directory for the code coverage report. --> 
               <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory> 
              </configuration> 
             </execution> 
            </executions> 
           </pluginExecutionFilter> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

war mein letzter Versuch, aber die pom wird größer und größer ohne Ergebnis

die Failes mit

Konfiguration Bericht Plugin org.apache.maven.plugins: Maven-jxr-Plugin: 2.3

Konfiguration Bericht org.jacoco Plugin: jacoco-Maven-Plugin: 0.7.5.201505241946

Skipping JaCoCo Ausführung durch Ausführung Datendatei fehlt: ...... \ target \ jacoco.exec

Skipping JaCoCo Ausführung aufgrund fehlender Dateiausführungsdaten: ...... \ target \ jacoco-it .exec

....=> Langer Projektpfad

+1

Verwendung so etwas wie das jacoco Plugin oder dem cobertura Plugin. Was ist das? Sie sagen, Sie haben das schon ausprobiert und es ist "kläglich gescheitert"? Hmmm. Nun, wenn ich wüsste, was "kläglich gescheitert" * aussah, * könnte ich vielleicht helfen, aber so wie es ist, denke ich, dass du kein Glück hast. – dcsohl

+0

Sie verwenden das 'jacoco-maven-plugin'? Erkläre, was du getan hast und probier es bitte, dann könnten wir Ale sein, um zu helfen. – RobAu

+0

die pom Fragmente für jacoco zur Frage hinzugefügt – user3732793

Antwort

6

wie immer die Lösung ist einfach, nach dem Lesen der Dokumentation, die beispielsweise Poms jacoco documentation

Profil

<profile> 
     <id>test</id> 
     <properties> 
      <env>test</env> 
      <gebEnv>test</gebEnv> 
      <jacoco.skip>false</jacoco.skip> 
      <maven.test.skip>false</maven.test.skip> 
      <skip.unit.tests>false</skip.unit.tests> 
     </properties> 
    </profile> 

dies in dem Build-Abschnitt enthält

 <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>${jacoco.version}</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>prepare-agent</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>report</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>report</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

und dies in der Berichtsabteilung

 <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>${jacoco.version}</version> 
     </plugin> 

als dies tut alles

mvn sauber Website -P Test

dank

3

Dank installieren user3732793

personnaly ich dies nur notwendig, um in den meine pom.xml

<project> 
... 

    <dependencies> 
     ... 
    </dependencies> 

    <build> 
     <plugins> 
      ... 
      <!-- Code Coverage report generation --> 
      <plugin> 
       <groupId>org.jacoco</groupId> 
       <artifactId>jacoco-maven-plugin</artifactId> 
       <version>0.7.9</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>prepare-agent</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>generate-code-coverage-report</id> 
         <phase>test</phase> 
         <goals> 
          <goal>report</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Dann laufe ich

mvn test 

und ich erhalte den HTML-Bericht unter ./target/site/jacoco/*.html

+0

ziemlich lange Zeit seit dem Problem passiert, danke für die Freigabe sowieso – user3732793