今天继续写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。
(Visited 252 times, 1 visits today)
发表评论