﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-开心幸福生活每一天。。。-随笔分类-ant</title><link>http://www.blogjava.net/baopei/category/26055.html</link><description>JPLT2が合格しましたが、会話と聴力はまだまだです。これからも、がんばれ！！！</description><language>zh-cn</language><lastBuildDate>Thu, 29 Jul 2010 11:29:14 GMT</lastBuildDate><pubDate>Thu, 29 Jul 2010 11:29:14 GMT</pubDate><ttl>60</ttl><item><title>用Ant编译、junit测试、生成测试报告、最终自动发mail</title><link>http://www.blogjava.net/baopei/archive/2009/03/13/259534.html</link><dc:creator>鮑佩</dc:creator><author>鮑佩</author><pubDate>Fri, 13 Mar 2009 06:32:00 GMT</pubDate><guid>http://www.blogjava.net/baopei/archive/2009/03/13/259534.html</guid><wfw:comment>http://www.blogjava.net/baopei/comments/259534.html</wfw:comment><comments>http://www.blogjava.net/baopei/archive/2009/03/13/259534.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/baopei/comments/commentRss/259534.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baopei/services/trackbacks/259534.html</trackback:ping><description><![CDATA[<p>红色部分是自己所写，黑色部分是参照别人的。。。<br />
测试通过的版本如下:<br />
Eclipse:3.3.2<br />
jdk:1.6<br />
junit:3.8<br />
ant:1.7(1.7之前的版本好像还不提供mail功能。。。)<br />
<br />
&lt;!-- JUnit build script using ant 1.7 --&gt;<br />
&lt;project name="JunitTestProject" default="mail" basedir="."&gt;<br />
&nbsp;&lt;property name="app.name" value="JunitTestProject" /&gt;<br />
&nbsp;&lt;property name="build.dir" value="bin" /&gt;</p>
<p>&nbsp;&lt;!-- ====================" path&nbsp; define&nbsp; " ================================ --&gt;<br />
&nbsp;&lt;path id="cobertura.classpath"&gt;<br />
&nbsp;&nbsp;&lt;fileset dir="lib/coberture"&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;include name="cobertura.jar" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;include name="*.jar" /&gt;<br />
&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&lt;/path&gt;<br />
&nbsp;&lt;!-- ====================" cobertura task define&nbsp; " Target ================================ --&gt;<br />
&nbsp;&lt;taskdef classpathref="cobertura.classpath" resource="tasks.properties" /&gt;</p>
<p>&nbsp;&lt;!-- ==================== "clean " Target ================================ --&gt;<br />
&nbsp;&lt;target name="clean"&gt;<br />
&nbsp;&nbsp;&lt;available property="junit.present" classname="junit.framework.TestCase" /&gt;<br />
&nbsp;&nbsp;&lt;delete dir="${build.dir}" quiet="true" /&gt;<br />
&nbsp;&nbsp;&lt;delete file="report" quiet="true" /&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p>&nbsp;&lt;!-- ==================== "copy xml resource " Target ================================ --&gt;<br />
&nbsp;&lt;target name="copyxml" depends="clean"&gt;<br />
&nbsp;&nbsp;&lt;copy todir="${build.dir}/testcases"&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;fileset dir="WEB-INF" /&gt;<br />
&nbsp;&nbsp;&lt;/copy&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p>&nbsp;&lt;!-- ==================== "compile&nbsp; src" Target ================================ --&gt;<br />
&nbsp;&lt;target name="compile" depends="copyxml"&gt;<br />
&nbsp;&nbsp;&lt;mkdir dir="${build.dir}" /&gt;<br />
&nbsp;&nbsp;&lt;javac srcdir="src" destdir="${build.dir}" debug="yes"&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;classpath&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileset dir="lib" casesensitive="yes"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="**/*.jar" /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/classpath&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;include name="**/*.java" /&gt;<br />
&nbsp;&nbsp;&lt;/javac&gt;<br />
&nbsp;&nbsp;&lt;javac srcdir="WEB-INF" destdir="${build.dir}"&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;classpath&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileset dir="lib" casesensitive="yes"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="**/*.jar" /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/classpath&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;include name="*.jsp" /&gt;<br />
&nbsp;&nbsp;&lt;/javac&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p>&nbsp;&lt;!-- ==================== jar" Target ================================ --&gt;<br />
&nbsp;&lt;target name="jar" depends="compile"&gt;<br />
&nbsp;&nbsp;&lt;mkdir dir="dist/lib" /&gt;<br />
&nbsp;&nbsp;&lt;jar jarfile="dist/lib/${app.name}.jar" basedir="${build.dir}" includes="com/**" /&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p>&nbsp;&lt;!-- ==================== compile test src" Target ================================ --&gt;<br />
&nbsp;&lt;target name="compiletests" depends="jar"&gt;<br />
&nbsp;&nbsp;&lt;mkdir dir="${build.dir}/testcases" /&gt;<br />
&nbsp;&nbsp;&lt;javac srcdir="test" destdir="${build.dir}/testcases" &gt;<br />
&nbsp;&nbsp;&nbsp;&lt;classpath&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileset dir="lib" casesensitive="yes"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="**/*.jar" /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileset dir="dist/lib" casesensitive="yes"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="**/*.jar" /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/classpath&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;include name="**/*.java" /&gt;<br />
&nbsp;&nbsp;&lt;/javac&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p>&nbsp;&lt;!-- ==================== instrumented" Target ================================ --&gt;<br />
&nbsp;&lt;target name="instrumented" depends="compiletests"&gt;<br />
&nbsp;&nbsp;&lt;cobertura-instrument todir="bin/instrumented-classes"&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;ignore regex="org.apache.log4j.*" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;fileset dir="bin"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="com/**/*.class" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&lt;/cobertura-instrument&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p>&nbsp;&lt;!-- ==================== junit-test" Target ================================ --&gt;<br />
&nbsp;&lt;target name="runtests" depends="instrumented"&gt;<br />
&nbsp;&nbsp;&lt;mkdir dir="report" /&gt;<br />
&nbsp;&nbsp;&lt;property name="tests" value="*Test" /&gt;<br />
&nbsp;&nbsp;&lt;junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes"&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&lt;formatter type="plain" usefile="false" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;formatter type="xml" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;batchtest todir="report"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileset dir="test"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="**/${tests}.java" /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;exclude name="**/ConfigTest.java" /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/batchtest&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;!--<br />
&nbsp;&nbsp;&nbsp;&nbsp;Note the classpath order: instrumented classes are before the<br />
&nbsp;&nbsp;&nbsp;&nbsp;original (uninstrumented) classes.&nbsp; This is important.<br />
&nbsp;&nbsp;&nbsp;--&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;classpath location="bin/instrumented-classes" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;!--<br />
&nbsp;&nbsp;&nbsp;&nbsp;src classpath<br />
&nbsp;&nbsp;&nbsp;--&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;classpath location="bin" /&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&lt;!--<br />
&nbsp;&nbsp;&nbsp;&nbsp;The instrumented classes reference classes used by the<br />
&nbsp;&nbsp;&nbsp;&nbsp;Cobertura runtime, so Cobertura and its dependencies<br />
&nbsp;&nbsp;&nbsp;&nbsp;must be on your classpath.<br />
&nbsp;&nbsp;&nbsp;--&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;classpath refid="cobertura.classpath" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;!--<br />
&nbsp;&nbsp;&nbsp;&nbsp;test case class path define<br />
&nbsp;&nbsp;&nbsp;--&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;classpath&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileset dir="lib" casesensitive="yes"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="**/*.jar" /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement location="bin/testcases" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/classpath&gt;<br />
&nbsp;&nbsp;&lt;/junit&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p>&nbsp;&lt;!-- ==================== junit-report" Target ================================ --&gt;<br />
&nbsp;&lt;target name="report" depends="runtests"&gt;<br />
&nbsp;&nbsp;&lt;mkdir dir="report/html" /&gt;<br />
&nbsp;&nbsp;&lt;junitreport todir="report"&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;fileset dir="report"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="TEST-*.xml" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;report todir="report/html" /&gt;<br />
&nbsp;&nbsp;&lt;/junitreport&gt;<br />
&nbsp;&lt;/target&gt;</p>
<p><br />
&nbsp;&lt;!-- ==================== "coverage-report" Target ================================ --&gt;<br />
&nbsp;&lt;target name="coverage-report" depends="report"&gt;<br />
&nbsp;&nbsp;&lt;cobertura-report format="html" destdir="cobertura" &gt;<br />
&nbsp;&nbsp;&nbsp;&lt;fileset dir="src"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="**/*.java" /&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&lt;/cobertura-report&gt;<br />
&nbsp;&nbsp;&lt;echo&gt;The execution of coverage-report is complete. Coverage Reports are available in /${coverage-report}&lt;/echo&gt;<br />
&nbsp;&lt;/target&gt;<br />
&nbsp;<br />
&nbsp;<span style="color: red">&lt;!-- ==================== "make file to zip" Target ================================ --&gt;<br />
&nbsp;&lt;target name="make_data_zip" depends="coverage-report"&gt;<br />
&nbsp;&nbsp;&lt;tstamp&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;format property="date" pattern="yyyy-MM-dd HH-mm" /&gt;<br />
&nbsp;&nbsp;&lt;/tstamp&gt;<br />
&nbsp;&nbsp;&lt;jar jarfile="dist/lib/cobertura${date}.zip" basedir="cobertura" /&gt;<br />
&nbsp;&nbsp;&lt;jar jarfile="dist/lib/report${date}.zip" basedir="report" excludes="*.xml"/&gt;<br />
&nbsp;&lt;/target&gt;<br />
</span></p>
<p><span style="color: red">&lt;!-- ==================== "mail" Target ================================ --&gt;<br />
&nbsp;&lt;target name="mail" depends="make_data_zip"&gt;<br />
&nbsp;&nbsp;&lt;!-- &lt;taskdef name="mail" classname="org.apache.tools.ant.taskdefs.optional.mail.MimeMail"/&gt; --&gt;<br />
&nbsp;&nbsp;&lt;tstamp/&gt;<br />
&nbsp;&nbsp;&lt;mail messageMimeType="text/html"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; messageFile="message.txt"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tolist="</span><a href="mailto:bpcjy@hotmail.com"><span style="color: red">bpcjy@hotmail.com</span></a><span style="color: red">"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mailhost="mailsvr or mail IPAddress"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; subject="JUnit Test Results: ${TODAY}"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from="</span><a href="mailto:bpcjy@hotmail.com"><span style="color: red">bpcjy@hotmail.com</span></a><span style="color: red">"&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;fileset dir="."&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;include name="dist/lib/*.zip"/&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/fileset&gt;<br />
&nbsp;&nbsp;&lt;/mail&gt;<br />
&nbsp;&lt;/target&gt;</span></p>
<p>&lt;/project&gt;<br />
</p>
   <img src ="http://www.blogjava.net/baopei/aggbug/259534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baopei/" target="_blank">鮑佩</a> 2009-03-13 14:32 <a href="http://www.blogjava.net/baopei/archive/2009/03/13/259534.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>antのbuild.xmlの中に、junitのtagを見つかれない</title><link>http://www.blogjava.net/baopei/archive/2007/09/21/147111.html</link><dc:creator>鮑佩</dc:creator><author>鮑佩</author><pubDate>Fri, 21 Sep 2007 06:51:00 GMT</pubDate><guid>http://www.blogjava.net/baopei/archive/2007/09/21/147111.html</guid><wfw:comment>http://www.blogjava.net/baopei/comments/147111.html</wfw:comment><comments>http://www.blogjava.net/baopei/archive/2007/09/21/147111.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/baopei/comments/commentRss/147111.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/baopei/services/trackbacks/147111.html</trackback:ping><description><![CDATA[<p>在eclipse中使用ant脚本、调用junit的task时会出现上述错误，解决方法：<br />
1。将junit.jar 拷贝到eclipse的ant插件的目录下的lib中</p>
<p>2。在eclipse-&gt;windows-&gt;ant-&gt;runtime中设置ant加载的jar，增加一个外部的jar，将<br />
&nbsp;&nbsp;&nbsp;&nbsp; 添加的junit.jar加入到ant的classpath中。</p>
<br />
2009-03-12<br />
现在遇到这个问题，按照上面作没有用了，难道是jdk，junit.jar包和eclipse的版本冲突了？请知道的朋友告诉我一下。。。 <br />
<p>Buildfile: E:\02_STUDY\07_Java\workspace\JunitTestProject\build.xml<br />
clean:<br />
&nbsp;&nbsp; [delete] Deleting directory E:\02_STUDY\07_Java\workspace\JunitTestProject\bin<br />
&nbsp;&nbsp; [delete] Directory E:\02_STUDY\07_Java\workspace\JunitTestProject\report cannot be removed using the file attribute.&nbsp; Use dir instead.<br />
copyxml:<br />
&nbsp;&nbsp;&nbsp;&nbsp; [copy] Copying 10 files to E:\02_STUDY\07_Java\workspace\JunitTestProject\bin\testcases<br />
compile:<br />
&nbsp;&nbsp;&nbsp; [javac] Compiling 20 source files to E:\02_STUDY\07_Java\workspace\JunitTestProject\bin<br />
&nbsp;&nbsp;&nbsp; [javac] 注意：E:\02_STUDY\07_Java\workspace\JunitTestProject\src\com\ustcsoft\struts1\action\SampleAction.java 使用或覆盖了已过时的 API。<br />
&nbsp;&nbsp;&nbsp; [javac] 注意：要了解详细信息，请使用 -Xlint:deprecation 重新编译。<br />
jar:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [jar] Building jar: E:\02_STUDY\07_Java\workspace\JunitTestProject\dist\lib\JunitTestProject.jar<br />
compiletests:<br />
&nbsp;&nbsp;&nbsp; [javac] Compiling 14 source files to E:\02_STUDY\07_Java\workspace\JunitTestProject\bin\testcases<br />
&nbsp;&nbsp;&nbsp; [javac] 注意：某些输入文件使用或覆盖了已过时的 API。<br />
&nbsp;&nbsp;&nbsp; [javac] 注意：要了解详细信息，请使用 -Xlint:deprecation 重新编译。<br />
&nbsp;&nbsp;&nbsp; [javac] 注意：E:\02_STUDY\07_Java\workspace\JunitTestProject\test\com\ustcsoft\struts2\action\ConfigTest.java 使用了未经检查或不安全的操作。<br />
&nbsp;&nbsp;&nbsp; [javac] 注意：要了解详细信息，请使用 -Xlint:unchecked 重新编译。<br />
instrumented:<br />
[cobertura-instrument] Cobertura 1.9.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file<br />
[cobertura-instrument] Cobertura: Loaded information on 20 classes.<br />
[cobertura-instrument] Instrumenting 20 files to E:\02_STUDY\07_Java\workspace\JunitTestProject\bin\instrumented-classes<br />
[cobertura-instrument] Cobertura: Saved information on 20 classes.<br />
[cobertura-instrument] Instrument time: 203ms<br />
runtests:<br />
&nbsp;&nbsp;&nbsp; [junit] Running com.ustcsoft.homework.logic.impl.HomeWorkLogicImplTest<br />
&nbsp;&nbsp;&nbsp; [junit] java.lang.NoClassDefFoundError: org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner<br />
&nbsp;&nbsp;&nbsp; [junit] Exception in thread "main"</p>
<p>BUILD FAILED<br />
E:\02_STUDY\07_Java\workspace\JunitTestProject\build.xml:88: Test com.ustcsoft.homework.logic.impl.HomeWorkLogicImplTest failed</p>
<p>Total time: 3 seconds<br />
</p>
 <img src ="http://www.blogjava.net/baopei/aggbug/147111.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/baopei/" target="_blank">鮑佩</a> 2007-09-21 14:51 <a href="http://www.blogjava.net/baopei/archive/2007/09/21/147111.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>