ant - junit 和 ant 问题。无法开始测试

标签 ant junit

当我从 ant 运行 junit 测试时,我总是得到:

D:\metrike>ant test
Buildfile: build.xml

init:

compile:

test:
    [junit] Running jmt.test.TestCodeBase
    [junit] Testsuite: jmt.test.TestCodeBase
    [junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0,046 sec
    [junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0,046 sec
    [junit]
    [junit] Testcase: warning(junit.framework.TestSuite$1):     FAILED
    [junit] No tests found in jmt.test.TestCodeBase
    [junit] junit.framework.AssertionFailedError: No tests found in jmt.test.TestCodeBase
    [junit]
    [junit]
    [junit] Test jmt.test.TestCodeBase FAILED

这是 ant 文件:

<target name="test" depends="compile">
    <mkdir dir="target/test-results"/>
    <junit haltonfailure="no" printsummary="on">
        <classpath >
            <pathelement location="target/classes"/>
            <pathelement location="Libraries/junit3.8.1/junit.jar"/>
        </classpath>
        <formatter type="brief" usefile="false"/>
        <formatter type="xml" />
        <batchtest todir="target/test-results" >
            <fileset dir="target/classes" includes="**/TestCodeBase.class"/>
        </batchtest>
    </junit>
</target>

但是当我手动运行测试时,junit 测试有效:

D:\metrike>cd target

D:\metrike\target>cd classes

D:\metrike\target\classes>java jmt.test.TestCodeBase
fatsource.jar eclapsed : 2297 ms
over all : 2297 ms
contains 3073 classes and 3700 referred classes, 35968 referred methods, 22351 referred fields
Memory usage: 21326 KB
Post gc-memory usage: 19506 KB
contains 3073 classes and 3700 referred classes, 35968 referred methods, 22351 referred fields

有人可以告诉我我做错了什么吗?我一整天都在尝试解决这个问题,但找不到解决方案。

最佳答案

1)jmt.test.TestCodeBase是否扩展TestCase(junit.framework.TestCase)?

如果没有,则需要由 junit ant 任务拾取。

2) 该类是作为 junit TestCase 编写的,还是只是从 main 方法中调用?请参阅this link以 Junit3 风格编写简单测试的示例。对于Junit4,只需在方法上方添加@Test即可。

3)测试方法是Junit3风格(每个方法都以test开头)还是Junit4风格(每个方法上面都有一个@Test)?

如果是 Junit3,你应该可以开始了。如果是 Junit4,您需要在 ant 类路径中包含 Junit4 测试库,而不是使用 junit3.8.1。

关于ant - junit 和 ant 问题。无法开始测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3803380/

相关文章:

java - 如何模拟 getApplicationContext

java - AssertJ - 方法 isEqualToComparingFieldByFieldRecursively 不适用于 RuntimeException 对象

Java/JUnit 过滤重复条件

java - Apache NetBeans 9.0 ant 构建失败

eclipse - 防止 eclipse 在运行 Ant 任务之前构建项目

ant - 捕获 Ant <javadoc> 任务输出

java - Ant: ":"和 ";"作为分隔符未在类路径中正确读取

java - Ant 的运行时类路径找不到 javac 的依赖项

java - MyBatis映射@One注解问题

java - 与 JUnit 一起运行时,Intellij IDEA 不会在 Kotlin 断点处停止