支持SRC /和测试简单的Ant构建脚本/? [英] Simple ant build script that supports src/ and test/?

查看:121
本文介绍了支持SRC /和测试简单的Ant构建脚本/?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我用我所有的构建和单元测试的IDE。现在我有一个需要使用蚂蚁。我发现了几个简单的Ant build.xml脚本,但他们不支持单独的JUnit测试/目录。我的项目结构如下:

Currently I use an IDE for all my builds and unit tests. Now I have a need to use ant. I found a few simple ant build.xml scripts but they didn't support a separate Junit test/ dir. My projects are structured as follows:


src/
  com/foo/
  com/bar/

test/ -- Mirror of src/, with all *Test.java files.
  com/foo/ 
  com/bar/

lib/  -- All Java libs, including junit 4.

如何才能构造,建立我的src /和测试/ Java类,然后小蚂蚁脚本运行我的JUnit测试?

How can a construct a small ant script that builds my src/ and test/ Java classes then runs all my JUnit tests?

推荐答案

我定义<路径方式>为每个目标元素

这是从我的构建文件的摘录,你必须去适应一些路径和属性,但你可以得到的想法:

This is an excerpt from my build file, you'll have to adapt some paths and properties, but you can get the idea:

<path id="src.path">    
    <pathelement path="src/"/>
</path>

<path id="compile.path">
    <path refid="src.path"/>
    <fileset dir="lib/">
        <include name="**/*.jar"/>
    </fileset>
</path>

<path id="unit.test.path">
    <path refid="compile.path"/>
    <pathelement path="test/"/>
</path>

<target name="compile">
    <javac destdir="bin">
        <src path="src"/>
        <classpath refid="compile.path"/>
    </javac>
</target>

<target name="compileUnitTests" depends="compile">
    <javac srcdir="test/" destdir="bin">
        <classpath refid="unit.test.path"/>
    </javac>
</target>

<target name="runUnitTests" depends="compileUnitTests">
    <junit printsummary="yes" haltonfailure="no">
    <jvmarg value="-Dfile.encoding=UTF-8"/>
        <classpath refid="unit.test.path"/>

        <formatter type="xml"/>

        <batchtest fork="yes" todir="${this.report}">
            <fileset dir="test">
                <include name="${test.pattern}"/>
                <exclude name="**/AllTests.class"/>
                <exclude name="**/*$*.class"/>
            </fileset>
        </batchtest>
    </junit>
</target>

如果你需要改进给你的需求,cotton.m说,去阅读Ant任务的文档。使用Ant与特定的目录结构确实需要工具有一定的了解,不要期望你会很容易找到现成的例子,只是与您的具体要求工作。

And if you need to refine this to your needs, as cotton.m says, go read the ant task docs. Using ant with your specific directory structure does require some knowledge of the tool, don't expect you'll easily find ready-made examples that just work with your exact requirements.

这篇关于支持SRC /和测试简单的Ant构建脚本/?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆