Pessoal estou com uma duvida aqui nunca mexi com o Ant e estou tentado usa-lo para chamar minha classe de teste do JUnit.
Achei um exemplo do Ant simples aqui e estou tentando seguir e entende-lo.
<project name="ProjetoJUnit" default="rodarTestes" basedir=".">
<property name="src" value="src" />
<property name="src.testes" value="src\testes" />
<target name="rodarTestes" description="Roda todos os testes!">
<echo>Executando Testes...</echo>
<junit fork="yes" printsummary="no">
<classpath refid="project.classpath" />
<formatter type="plain" usefile="false" />
<batchtest>
<fileset dir="${src.testes}">
<include name="ExecutarTodosTestes.java" />
</fileset>
</batchtest>
</junit>
</target>
</project>
Minha classe de Teste:
@RunWith(value = Suite.class)
@SuiteClasses(value = { TesteNumerico.class, TesteDataUtil.class })
public class ExecutarTodosTestes {
}
O problema é que não sei o que colocar em <classpath refid="project.classpath" />
ai gera o erro: Reference project.classpath not found.
Pessoal desculpe se eu falei alguma bobeira, é que eu realmente não entendo dessas ferramentas.
Muito Bem Explicado aqui! Ainda estou testando!
http://uaihebert.com/?p=60
<?xml version="1.0" encoding="UTF-8"?>
<project name="Emma Reports" basedir="." default="00-GenerateReport">
<!-- Project Source Code -->
<property name="src.dir" value="src" />
<property name="bin.dir" value="bin" />
<property name="teste.dir" value="src/test" />
<property name="lib.dir" value="lib" />
<!-- Emma source code -->
<property name="emma.bin.dir" value="emma/bin" />
<property name="emma.metadate.dir" value="emma/metadate" />
<property name="emma.report.dir" value="emma/report" />
<!-- Tested Class -->
<property name="ExecutarTodosTestes" value="${teste.dir}.ExecutarTodosTestes" />
<!-- Project classpath -->
<path id="project.classpath">
<pathelement location="${bin.dir}" />
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<!-- Emma task definitions that you will find inside the jar -->
<taskdef resource="emma_ant.properties">
<classpath refid="project.classpath" />
</taskdef>
<!-- JUnit task definition -->
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />
<!-- Clean UP Your Code -->
<target name="01-CleanUp">
<delete dir="${bin.dir}" />
<mkdir dir="${bin.dir}" />
</target>
<!-- Compile Your Code -->
<target name="02-CompileSourceCode" depends="01-CleanUp">
<javac debug="on" srcdir="${src.dir}" destdir="${bin.dir}">
<classpath refid="project.classpath" />
</javac>
<copy file="${src.dir}/META-INF/persistence.xml" todir="${bin.dir}/META-INF" />
</target>
<!-- Generate the Emma -->
<target name="03-Instrumentation" depends="02-CompileSourceCode">
<emma>
<instr instrpath="${bin.dir}" destdir="${emma.bin.dir}" metadatafile="${emma.metadate.dir}/metadate.emma" merge="false" mode="fullcopy" />
</emma>
</target>
<!-- Runs JUnit Tests -->
<target name="04-RunTests" depends="03-Instrumentation">
<junit haltonfailure="false" haltonerror="false" fork="true">
<classpath>
<pathelement location="${emma.bin.dir}/classes" />
<pathelement location="${emma.bin.dir}/lib" />
<path refid="project.classpath" />
</classpath>
<formatter type="plain" usefile="false" />
<test name="${ExecutarTodosTestes}" />
<jvmarg value="-Demma.coverage.out.file=${emma.metadado.dir}/cobertura.emma" />
<jvmarg value="-Demma.coverage.out.merge=false" />
</junit>
</target>
<!-- Creates the report -->
<target name="00-GenerateReport" depends="04-RunTests">
<delete dir="${emma.report.dir}" />
<emma enabled="true">
<report sourcepath="${src.dir}" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">
<fileset dir="${emma.metadate.dir}">
<include name="*.emma" />
</fileset>
<html outfile="${emma.report.dir}/report.html" depth="method" columns="name,class,method,block,line" />
</report>
</emma>
<antcall target="05-DeleteOldReportData" />
</target>
<!-- Delete Old Report Data -->
<target name="05-DeleteOldReportData">
<delete dir="${emma.bin.dir}" />
<delete dir="${emma.metadate.dir}" />
</target>
</project>
Pessoal ta dando erro no no seguinte item:
<!-- Compile Your Code -->
<target name="02-CompileSourceCode" depends="01-CleanUp">
<javac debug="on" srcdir="${src.dir}" destdir="${bin.dir}">
<classpath refid="project.classpath" />
</javac>
<copy file="${src.dir}/META-INF/persistence.xml" todir="${bin.dir}/META-INF" />
</target>
Erro: Y:\Java\Fatec\2012_02 Curso Java\ProjetoJUnit\src\build.xml:43: srcdir “Y:\Java\Fatec\2012_02 Curso Java\ProjetoJUnit\src\src” does not exist!
Porem eu não estou achando onde estou criando src\src…
Achei o erro era no lugar que tava o build.xml … heheh
Para quem precisar de um exemplo. Segue o projeto!
é igual ao que usei de exemplo porem só coloquei relatórios do JUnit
https://snt131.mail.live.com/default.aspx?id=64855#!https://skydrive.live.com/?sc=documents&cid=4c800dd30fdeb3cc!cid=4C800DD30FDEB3CC&id=4C800DD30FDEB3CC%211082&sc=documents