У меня большая проблема со сборкой моего проекта для тестирования junit в сонаре и увеличения покрытия кода.
Я делаю сборку, но что-то не работает. Я использую java, ant, jacoco и junit.
Я изменил свою сборку. xml, чтобы сделать работу с junit и jacoco. Но ничего, я не понимаю, в чем дело.
Это исключение для всех тестовых классов:
java.lang.ClassNotFoundException: test.java.com.intesasanpaolo.ibsm.test.TestContainsFilter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
Это сборка. xml
<project default="all_task" xmlns:ivy="antlib:org.apache.ivy.ant" name="ibsm">
<property environment="env" />
<property file="${env.ANTPROPERTIES}" />
<property file="build.properties" />
<path id="cp">
<fileset dir="lib" />
<fileset dir="provided-lib" />
</path>
<target name="ivy-check">
<available file="${user.home}/.ant/lib/ivy.jar" property="ivy.isInstalled"/>
</target>
<target name="bootstrap" description="Install ivy" depends="ivy-check" unless="ivy.isInstalled">
<!-- <mkdir dir="${basedir}/lib"/>
<get dest="${basedir}/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>-->
<echo> Ivy non disponibile </echo>
</target>
<target name="resolve" depends="bootstrap" description="Download dependencies and setup classpaths">
<ivy:resolve/>
<ivy:report todir='${reports.dir}/ivy' graph='false' xml='false'/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="test.path" conf="test"/>
<ivy:cachepath pathid="build.path" conf="build"/>
</target>
<!-- *ADD_CI* -->
<!-- ==================================================================== -->
<!-- WAR COMPILATION WITH Test Class -->
<!-- ==================================================================== -->
<!-- *ADD_CI* -->
<target name="web_compt">
<javac srcdir ="${web.srccomp.dir}"
destdir="${web.destcomp.dir}"
includeantruntime="false"
encoding="UTF-8" debug="yes" classpathref="cp"
target="1.7" source="1.7" >
<include name="main/java/com/intesasanpaolo/ibsm/**/*.java"/>
<classpath>
<path refid="compile.path"/>
<fileset dir="${j2ee.lib.dir}">
<include name="${j2ee.lib.jar}"/>
</fileset>
<fileset dir="${path_tmp}/provided-lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${path_tmp}/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
<!-- <javac srcdir ="${web.srccomp.dir}"
destdir="${web.destcomp.dir}"
includeantruntime="false"
fork="yes"
debug="true"
executable="${project_javahome}/bin/javac"
target="1.7"
compiler="${compiler}">
<include name="main/java/com/intesasanpaolo/ibsm/**/*.java"/>
<classpath>
<path refid="compile.path"/>
<fileset dir="${j2ee.lib.dir}">
<include name="${j2ee.lib.jar}"/>
</fileset>
<fileset dir="${path_tmp}/provided-lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${path_tmp}/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
-->
</target>
<!-- *END_CI* -->
<!-- *ADD_CI* -->
<!-- ================================================================== -->
<!-- Execute Unit Test -->
<!-- ================================================================== -->
<!-- *ADD_CI* -->
<target name="unit_test" depends="resolve,web_compt">
<echo>____________________ unit_test start _________________________</echo>
<delete dir="${classtest.dir}"/>
<mkdir dir="${classtest.dir}"/>
<delete dir="{$classxsonar.dir}"/>
<mkdir dir="${classxsonar.dir}"/>
<delete dir="${reports.junit}"/>
<mkdir dir="${reports.junit}"/>
<delete dir="${reports.html}"/>
<mkdir dir="${reports.html}"/>
<delete dir="${reports.jacoco}"/>
<mkdir dir="${reports.jacoco}"/>
<copy todir="${web.destcomp.dir}">
<fileset dir="${web.srccomp.dir}">
<include name="main/resources/*.properties"/>
</fileset>
</copy>
<copy todir="${classtest.dir}">
<fileset dir="${web.root.dest}/target/classes" >
<include name="**/*Tests.class" />
<include name="**/*Test.class"/>
<include name="**/*Test*.properties"/>
</fileset>
</copy>
<copy todir="${classxsonar.dir}">
<fileset dir="${web.root.dest}/target/classes" >
<include name="**/*.class" />
<exclude name="**/*Tests.class" />
<exclude name="**/*Test.class"/>
<exclude name="**/*Test*.properties"/>
</fileset>
</copy>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpathref="build.path">
<classpath path="${path_lib_build}/${jacoco.lib.jar}"/>
</taskdef>
<jacoco:coverage destfile="${reports.jacoco}/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<junit fork="yes" forkmode="once" haltonfailure="no" showoutput="no"
printsummary="yes" errorProperty="test.failed"
failureProperty="test.failed">
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<jvmarg value="-Dconfigfile.path=${path_img}/WLSCONFIGDIR10/"/>
<classpath>
<pathelement location="${web.destcomp.dir}"/>
<path refid="build.path"/>
</classpath>
<batchtest fork="yes" todir="${reports.junit}">
<fileset dir="${web.srccomp.dir}">
<include name="test/java/com/intesasanpaolo/ibsm/**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<junitreport todir="${reports.junit}">
<fileset dir="${reports.junit}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports.html}"/>
</junitreport>
<condition property="msg" value="one or more unit tests failed"
else="unit tests all passed">
<isset property="test.failed" />
</condition>
<echo message="unit tests: "${msg}" ___" />
<jacoco:report xmlns:jacoco="antlib:org.jacoco.ant">
<executiondata>
<file file="${reports.jacoco}/jacoco.exec"/>
</executiondata>
<structure name="JaCoCo ibsm ">
<classfiles>
<fileset dir="${web.destcomp.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${web.srccomp.dir}"/>
</sourcefiles>
</structure>
<html destdir="${reports.jacoco}"/>
</jacoco:report>
<echo>____________________ unit_test end _________________________</echo>
</target>
<!-- *END_CI* -->
<target name="ear">
<tstamp>
<format property="build.time" pattern="yyyyMMddHHmm" unit="hour" />
</tstamp>
<delete dir="target"/>
<mkdir dir="target/classes"/>
<javac encoding="UTF-8" debug="yes" includeantruntime="no" classpathref="cp" srcdir="src/main/java" destdir="target/classes" target="1.7" source="1.7" />
<!-- application.properties, log4j.xml ecc. -->
<copy todir="target/classes">
<fileset dir="src/main/resources" />
</copy>
<copy todir="target/diraliases/WEBPORTALDIR/ibsm">
<fileset dir="src/main/webapp/portalLiq20" />
<!-- non suportato dall'ant base di isp -->
<!-- <cutdirsmapper dirs="1" /> -->
<filterset>
<filter token="versione" value="${build.time}" />
<filter token="acronimo" value="${ant.project.name}" />
</filterset>
</copy>
<echo message="versione: ${build.time}" file="target/classes/versione.txt" />
<fileset dir="lib" id="jar.files" includes="**/*" excludes="**/tomcat-embed*,**/spring-boot-starter-tomcat*,**/*logback"/>
<pathconvert pathsep=" " property="libs" refid="jar.files">
<map from="${basedir}/lib/" to="lib/" />
</pathconvert>
<copy todir="target">
<fileset dir="." includes="weblogic.xml, application-ear.xml" />
<filterset>
<filter token="acronimo" value="${ant.project.name}" />
</filterset>
</copy>
<war destfile="target/${ant.project.name}.war" needxmlfile="false">
<classes dir="target/classes" />
<lib refid="jar.files"/>
<manifest>
<attribute name="Class-Path" value="${libs}" />
</manifest>
<zipfileset dir="target" prefix="WEB-INF" includes="weblogic.xml" />
</war>
<ear destfile="target/diraliases/EARHOMEDIR/${ant.project.name}.ear" appxml="target/application-ear.xml">
<fileset dir="target" includes="${ant.project.name}.war" />
</ear>
</target>
<target name="all_task">
<antcall target="ear"/>
<antcall target="unit_test"/>
</target>
</project>
Плющ. xml
<ivy-module version="2.0">
<info organisation="org.adrian" module="demo"/>
<configurations defaultconfmapping="compile->default">
<conf name="compile" description="Required to compile application"/>
<conf name="test" description="Required for test only" extends="compile"/>
<conf name="build" description="Build dependencies"/>
</configurations>
<dependencies>
<!-- compile dependencies -->
<!-- set up your classpath here -->
<!-- ADD C.I. -->
<dependency org="junit" name="junit" rev="4.12" conf="compile->default"/>
<dependency org="org.mockito" name="mockito-all" rev="1.9.5" conf="compile->default"/>
<!-- END C.I. -->
<!-- test dependencies -->
<!-- build dependencies -->
<!-- ADD C.I. -->
<dependency org="junit" name="junit" rev="4.12" conf="build->default"/>
<dependency org="org.hamcrest" name="hamcrest-all" rev="1.3" conf="build->default"/>
<dependency org="org.mockito" name="mockito-all" rev="1.9.5" conf="build->default"/>
<!-- <dependency org="javax.servlet" name="javax.servlet-api" rev="3.1.0" conf="build->default"/> -->
<!-- END C.I. -->
<!-- Global exclusions -->
<exclude org="org.apache.ant"/>
</dependencies>
</ivy-module>
build.properties
<!-- *ADD_CI* -->
path_lib_test=${ant.home}/lib
path_lib_build=${ant.home}/lib
path_build_dir=${path_bin}/target
path_test_class=${path_build_dir}/test-classes
path_xsonar_class=${path_build_dir}/classes
path_reports=${path_build_dir}/reports
path_reports_junit=${path_reports}/junit
path_reports_html=${path_reports}/junit
path_reports_jacoco=${path_reports}/jacoco
#.............................................................................#
# test junit #
#.............................................................................#
build.dir=${path_build_dir}
classtest.dir=${path_test_class}
classxsonar.dir=${path_xsonar_class}
reports.dir=${path_reports}
reports.html=${path_reports_html}
reports.junit=${path_reports_junit}
reports.jacoco=${path_reports_jacoco}
jacoco.lib.jar=jacocoant.jar
path_vob=${team.scm.fetchDestination}
path_src=${path_vob}/liq20_SRC/SRC
path_bin=${path_src}/ibsm
path_tmp=${path_bin}
web.destcomp.dir=${path_tmp}/target/classes
j2ee_libpath=${weblogic_libpath_fullclient_10.3.6}
compiler=${compiler_1.6}
j2ee.lib.dir=${j2ee_libpath}
j2ee.lib.jar=wlfullclient.jar
project_javahome=${java_home_7}
target=${target_1.6}
web.root.dest=${path_tmp}
web.srccomp.dir=${path_src}/ibsm/src
bin.includes = SRC/
src.includes = SRC/
Есть предложения?