JUnit4和Ant的恩怨

今天继续写build脚本,加JUnit的target,但是我开始用的是Ant1.6.2,但是JUnit用的是4.1,发现编译正常,但是运行的时候出错,报的错是ClassNotFoundException,google了下,发现很多人有类似的问题,但是没有多少好的答案,最后在同事的一起努力下搞定,有两种情况:

  • 使用Ant1.6.2或者1.6.5的情况下,修改Test类,增加下面的方法:

public static junit.framework.Test suite() {
                return new JUnit4TestAdapter(TestXxxx.class);
}

还有就是注意ClassPath的定义:

    <path id="classpath">
        <fileset dir="${basedir}">
             <include name="lib/**/*.jar"/>
        </fileset>
        <fileset dir="${web.dir}">
              <include name="WEB-INF/lib/**/*.jar"/>
        </fileset>
  <pathelement path="${class.dir}"/>
    </path>

开始的时候,那个pathelement部分也是和其他的一样使用的fileset,不知道为什么必须使用pathelement才好使。

  • 使用Ant1.7.0的情况下,就不需要修改Test用那个什么JUnit4TestAdapter了。注意,好像Ant1.7.1有问题,可能是我的那个classpath搞的,没有仔细试过,报的错误是Can not open zip file,没有具体指出是那个zip文件找不到,根据google的一些结果建议回滚到Ant1.7.0。


作者: Cherami
原载: JUnit4和Ant的恩怨
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。

日志评价

1 Star2 Stars3 Stars4 Stars5 Stars (暂无评价) --点击星星直接投票
Loading ... Loading ...


相关日志

  • 暂时没有相关日志。


随机日志



添加到网摘

[del.icio.us]  [新浪 VIVI]  [365key]  [YouNote]  [博采中心]  [Poco]  [SOHU狐摘]  [天极网摘]  [和讯网摘]
喜欢这个插件?

当前日志信息