JUnit使用经验

<?xml version="1.0" encoding="UTF-8"?> <!-- ====================================================================== 2010-8-29 下午09:27:10 sampling description:using ant Administrator ====================================================================== --> <project name="sampling" default="default"> <property name="src.dir" location="src"/> <property name="src.java.dir" location="${src.dir}/java"/> <property name="src.test.dir" location="Test"/> <property name="target.dir" location="target"/> <property name="target.classes.java.dir" location="${target.dir}/classes/java"/> <property name="target.classes.test.dir" location="${target.dir}/classes/test"/> <description> description:using ant </description> <!-- ================================= target: default ================================= --> <target name="default" depends="test" description="description:using ant"> </target> <!-- - - - - - - - - - - - - - - - - - target: compile.java - - - - - - - - - - - - - - - - - --> <target name="compile.java"> <mkdir dir="${target.classes.java.dir}"/> <javac srcdir="${src.java.dir}" destdir="${target.classes.java.dir}" /> </target> <!-- - - - - - - - - - - - - - - - - - target: compile.test - - - - - - - - - - - - - - - - - --> <target name="compile.test"> <mkdir dir="${target.classes.test.dir}"/> <javac srcdir="${src.test.dir}" destdir="${target.classes.test.dir}" > <classpath> <pathelement location="${target.classes.java.dir}"/> </classpath> </javac> </target> <!-- ================================= target: test ================================= --> <target name="test" description="description"> <junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes"> <formatter type="plain" usefile="false"/> <test name="java.TestDefaultController" /> <classpath> <pathelement location="${target.classes.java.dir}"/> <pathelement location="${target.classes.test.dir}"/> </classpath> </junit> </target> <!-- - - - - - - - - - - - - - - - - - target: compile - - - - - - - - - - - - - - - - - --> <target name="compile" depends="compile.java,compile.test"> </target> </project>  

问题:在测试时,仔细验对了BUILD.XML代码,没有问题,可是在运行ANT时,出现unable to locate tools.jar

Expected to find it in d:/xx/java/jre1.6.0_04/lib/tools.jar,导致compile.java任务能执行,compile.test任务也能执行,但是并没有将编译好的class文件放在指定的文件夹中。

解决方法:查看jre1.6的lib确实无法找到tools.jar包,搜索之下发现,该工具包在JDK中,拷贝一份至jre中的lib下,可以正常工作了

 

问题:在执行javac任务时,总是提示warning: 'includeantruntimewas not setdefaulting to build.sysclasspath=lastset to false for repeatable build 

这个问题重不重要?

回答:

Historically, Ant always included its own runtime in the classpath 
made available to the javac task. So any libraries included with Ant, 
and any libraries available to ant, are automatically in your build's 
classpath whether you like it or not

就是设为true时,将自动包含ANT_HOME下的lib中所有类库,设为false将不自动包含,由于JUnit.jar已经被我放置在ANT的lib中,因此,这里需要设置为true

It was decided that this probably wasn't what most people wanted. So 
now there's an option for it. 

> Is it important? 

Yes. It calls your attention to an issue that can make your builds to 
work in unexpected ways. For an example, see item #3 at 
http://blogs.sun.com/kto/entry/painful_ant_bite_a_generous

If you choose "true", then at least you know that your build classpath 
will include the Ant runtime. If you choose "falsethen you are 
accepting the fact that the build behavior will change between older 
versions and 1.8+. 

> Who needs to know? I don't care. 

If you want your build file to have total control over your build
then you should care. 

> Why doesn't Ant just default to false and just omit warning me about this for every Ant build
> I don't want adjust every build file that I have. There are probably other ways, but it's annoying anyhow. 

As annoyed as you are to see this warning, you'd be even less happy if 
your builds broke entirely. Keeping this default behavior allows 
unmodified build files to work consistently between versions of Ant. 

 

问题:在Eclipse中,无法执行build.xml进行测试代码的编译,系统提示package   junit.framework   does   not   exist 

编译任务无法执行

解决:在Windows>>Preference>>Ant>>Runtime>>Classpath中添加junit.jar

你可能感兴趣的:(eclipse,ant,JUnit,任务,encoding,behavior)