gpt4 book ai didi

java - ANT 没有调用 JUnits

转载 作者:行者123 更新时间:2023-12-01 12:53:34 25 4
gpt4 key购买 nike

我是 ANT 新手,我正在尝试使用 ant 调用 Junit 测试(我使用的示例在这篇文章中提到非常简单)。问题是我没有看到测试用例被调用,因为我在屏幕上没有看到相关输出。 (在下面的消息中,Junit 之后没有日志,例如通过了多少测试)

Buildfile: C:\AntTestCases\build.xml
junit:
main:
BUILD SUCCESSFUL
Total time: 271 milliseconds

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="testingAnt" basedir="." default="main">

<!-- classpaths -->
<path id="classpath">
<fileset dir="lib" includes="**/*.jar"/>
</path>

<target name="junit">
<junit printsummary="on" fork="true" haltonfailure="yes">
<classpath>
<path refid="classpath"/>
</classpath>
<batchtest todir="reportDir">
<fileset dir="tests" includes="*Test.java"/>
</batchtest>
<formatter type="xml"/>
<formatter type="plain" usefile="false" />
</junit>
</target>

<target name="main" depends="junit"/>
</project>

directory structure

测试类

package suite;
import org.junit.Test;

import junit.framework.TestCase;

public class SampleTests extends TestCase{
@Test
public void test1() {
System.out.println("SampleTests.test1()");
assertTrue(true);
}
}

我非常感谢您对我出错的地方提出的意见。我读过一些关于 junit 和 ant 的教程,但没有任何帮助 http://www.vogella.com/tutorials/ApacheAnt/article.html http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html

Junit 的版本是 4,ant - 1.8.1 和 java 1.7

最佳答案

你需要类似的东西

      <batchtest todir="reportDir">
<fileset dir="tests" includes="**/*Test.java"/>
</batchtest>

关于java - ANT 没有调用 JUnits,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24043349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com