1
0
-1

Hi Avoka Team,

Is it possible to have our CI server produce a code coverage report? IntelliJ provides this capability but we can't utilise it from within Ant.

Thanks,

Sean

    CommentAdd your comment...

    4 answers

    1.  
      2
      1
      0

      Hi Sean

      Have you tried Jacoco?

      https://www.eclemma.org/jacoco/trunk/doc/ant.html

      Regards
      Rado

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi Rado,

        I've been attempting to get this working this morning. When I attempt to run the task as specified in IntelliJ IDEA I get the following message:

        Null Test: 	Caused an ERROR
        com.cusa.builders.newmembermessage.NewMemberMessageBuilderTest
        java.lang.ClassNotFoundException: com.cusa.builders.newmembermessage.NewMemberMessageBuilderTest
        	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
        	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
        	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
        	at java.base/java.lang.Class.forName0(Native Method)
        	at java.base/java.lang.Class.forName(Class.java:292)
        
        
        Test com.cusa.builders.newmembermessage.NewMemberMessageBuilderTest FAILED
        Loading execution data file /Users/scolyer/Documents/Code/avoka/cusa-forms/target/jacoco.exec
        Writing bundle 'My Project' with 0 classes
        
        
        

        Ideally we would define an Ant task that uses patterns to decide which files to test. I've put together a batch test tag to handle this:

        <jacoco:coverage destfile="target/jacoco.exec">
            <junit fork="true" forkmode="once">
                <classpath>
                    <pathelement location="./bin"/>
                    <fileset dir="../transact-sdk-17.10.0/lib">
                        <include name="**/*.jar" />
                    </fileset>
                </classpath>
                <batchtest todir="${collector.dir}">
                    <fileset dir="${basedir}/src">
                        <include name="**/*Test*.class"/>
                    </fileset>
                </batchtest>
                <formatter type="brief" usefile="false"/>
            </junit>
        </jacoco:coverage>

        But if I use this instead of the configuration you suggest above, I get the following message:

        BUILD FAILED
        
        /Users/scolyer/Documents/Code/avoka/cusa-forms/build.xml:21: java.lang.NoSuchMethodError: org.apache.tools.ant.types.resources.Resources.stream()Ljava/util/stream/Stream;
        
        	at org.apache.tools.ant.taskdefs.optional.junit.BatchTest.getFilenames(BatchTest.java:141)
        
        	at org.apache.tools.ant.taskdefs.optional.junit.BatchTest.createAllJUnitTest(BatchTest.java:126)
        
        	at org.apache.tools.ant.taskdefs.optional.junit.BatchTest.elements(BatchTest.java:102)
        
        	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.getIndividualTests(JUnitTask.java:1682)
        
        	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:853)
        
        	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
        
        	at org.jacoco.ant.CoverageTask.execute(CoverageTask.java:102)
        
        	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
        
        	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
        	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        
        	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        
        	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        
        	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        
        	at org.apache.tools.ant.Task.perform(Task.java:348)
        
        	at org.apache.tools.ant.Target.execute(Target.java:435)
        
        	at org.apache.tools.ant.Target.performTasks(Target.java:456)
        
        	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
        
        	at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
        
        	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        
        	at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
        
        	at org.apache.tools.ant.Main.runBuild(Main.java:857)
        
        	at org.apache.tools.ant.Main.startAnt(Main.java:236)
        
        	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:283)
        
        	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)

        In intelliJ, this does not cause an error, but does not appear to execute the tests.

        Any clues on how best to configure this for the Transact SDK would be appreciated!

        Thanks,

        Sean

          CommentAdd your comment...
        1.  
          1
          0
          -1

          We have not given a try much but one may create a similar task:

          <project name="my-project" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
          
              <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
                  <classpath path="path_to/lib/jacocoant.jar" />
              </taskdef>
          
              <target name="jacoco-task">
                  
                  <jacoco:coverage destfile="target/jacoco.exec">
                      <junit fork="true" forkmode="once">
                      <test name="com.mycompany.svc.ServiceTest"/>
                      <test  ... />
                      <test  ... />
                      <classpath>
                          <pathelement location="./bin"/>
                          <fileset dir="path_to_sdk/lib">
                              <include name="**/*.jar" />
                          </fileset>
                      </classpath>
                      <formatter type="brief" usefile="false"/>
                  </jacoco:coverage>
          
                  <jacoco:report>
                      <executiondata>
                          <file file="target/jacoco.exec"/>
                      </executiondata>
                      <structure name="My Project">
                          <classfiles>
                              <fileset dir="./bin"/>
                          </classfiles>
                          <sourcefiles encoding="UTF-8">
                              <fileset dir="src"/>
                          </sourcefiles>
                      </structure>
                      <html destdir="target/jacoco-report"/>
                  </jacoco:report>
              </target>
          </project>
            CommentAdd your comment...
          1.  
            1
            0
            -1

            Hi Rado,

            I did briefly try wrapping the svc-test and job in the build.xml with the Jacoco tags but I got an error telling me that it wasn't permitted. If this is how you are doing it would you mind sharing some configs?

            Thanks,

            Sean

              CommentAdd your comment...