JAVA CodeCov | CodeCov tests both main and test files, How to check only main files?

117 views Asked by At

I have a file name AVLTree.java, to test I have created AVLTreetest.java but codecov tests both src/main 80% and src/test 0% folder so due to that my score is reduced

This is my src directory

src 
  - main->java->avl_java_travis_cli->AVLTree.java
  - test->java->avl_java_travis_cli->AVLTreeTest.java

This is the shown error in codcov, 80% in main and 0% coverage in test, how to resolve this ? Thank you

enter image description here

build.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="avl_java_travis_cli">
<property environment="env"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<path id="JUnit 4.libraryclasspath">
    <pathelement location="C:/Users/ASUS/.p2/pool/plugins/org.junit_4.13.2.v20211018-1956.jar"/>
    <pathelement location="C:/Users/ASUS/.p2/pool/plugins/org.hamcrest.core_1.3.0.v20180420-1519.jar"/>
</path>
<path id="Maven Dependencies.libraryclasspath">
    <pathelement location="C:/Users/ASUS/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar"/>
    <pathelement location="C:/Users/ASUS/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
</path>
<path id="avl_java_travis_cli.classpath">
    <pathelement location="target/classes"/>
    <path refid="JUnit 4.libraryclasspath"/>
    <path refid="Maven Dependencies.libraryclasspath"/>
</path>
<path id="run.avl_java_travis_cli.classpath">
    <path refid="avl_java_travis_cli.classpath"/>
    <path refid="Maven Dependencies.libraryclasspath"/>
</path>
<target name="init">
    <mkdir dir="target/classes"/>
    <copy includeemptydirs="false" todir="target/classes">
        <fileset dir="src">
            <exclude name="**/*.launch"/>
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>
<target name="clean">
    <delete dir="target/classes"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" includeantruntime="false" source="${source}" target="${target}">
        <src path="src"/>
        <classpath refid="avl_java_travis_cli.classpath"/>
    </javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
    <copy todir="${ant.library.dir}">
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </copy>
    <unzip dest="${ant.library.dir}">
        <patternset includes="jdtCompilerAdapter.jar"/>
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
    <antcall target="build"/>
</target>
<target name="avl_java_travis_cli">
    <mkdir dir="${junit.output.dir}"/>
    <junit fork="yes" printsummary="withOutAndErr">
        <formatter type="xml"/>
        <test name="test.java.avl_java_travis_cli.AVLTreeTest" todir="${junit.output.dir}"/>
        <jvmarg line="-ea"/>
        <classpath refid="run.avl_java_travis_cli.classpath"/>
    </junit>
</target>
<target name="junitreport">
    <junitreport todir="${junit.output.dir}">
        <fileset dir="${junit.output.dir}">
            <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="${junit.output.dir}"/>
    </junitreport>
</target>

pom.xml

<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>avl_java_travis_cli</groupId>
    <artifactId>avl_java_travis_cli</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <name>avl_java_travis_cli</name>
    <url>http://cobertura.github.io/cobertura/</url>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src/main</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.7</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
1

There are 1 answers

0
Rohit gupta On BEST ANSWER

This resolved the issue after adding codecov.yml

I created codecov.yml in github

ignore
    -  "src/test"