Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java build.xml未运行junit测试用例_Java_Xml_Build_Junit4 - Fatal编程技术网

Java build.xml未运行junit测试用例

Java build.xml未运行junit测试用例,java,xml,build,junit4,Java,Xml,Build,Junit4,InsertionTest.java package efms.db.dao.impl; import java.util.Arrays; import java.util.Collection; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Para

InsertionTest.java

package efms.db.dao.impl;

import java.util.Arrays;
import java.util.Collection;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(value = Parameterized.class)
public class InsertionTest {

    int num1;
    int num2;
    int num3;

    public InsertionTest(int num1, int num2, int num3) {
        super();
        this.num1 = num1;
        this.num2 = num2;
        this.num3 = num3;
    }

    @Parameters
    public static Collection<Object[]> data() {
        Object[][] data = new Object[][] { { 1, 1, 2 }, { 2, 2, 4 } };
        return Arrays.asList(data);
    }

    @Test
    public void testSummationPositive() {
        Assert.assertEquals("Sum should be 4", num1 + num2, num3);
    }

}
我已经编写了一个简单的junit测试用例,当我运行build.xml时,文件正在编译,但当运行junit测试用例时,它显示了错误。我想build.xml有一些问题。能帮我修一下吗

在编写时:

          [javac] Compiling 1 source file to C:\Users\IBM_ADMIN\workspace1\Efms3.3\build\classes
junit:
     [echo] C:\Users\IBM_ADMIN\workspace1\Efms3.3//build/classes/
    [junit] Running efms.db.dao.impl.InsertionTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
    [junit] Test efms.db.dao.impl.InsertionTest FAILED
report:
[junitreport] Processing C:\Users\IBM_ADMIN\workspace1\Efms3.3\build\classes\TESTS-TestSuites.xml to C:\Users\IBM_AD~1\AppData\Local\Temp\null2013296782
[junitreport] Loading stylesheet jar:file:/C:/Rahul/RahulDrive/Software/Development%20Tools/Apache/apache-ant-1.9.2-bin/apache-ant-1.9.2/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 491ms
[junitreport] Deleting: C:\Users\IBM_AD~1\AppData\Local\Temp\null2013296782
all:
BUILD SUCCESSFUL
Total time: 3 seconds

Ant代码表示用于运行测试的类路径为:

<classpath>
    <pathelement location="${p}/lib/junit.jar" />
    <pathelement location="${p}/lib/hamcrest-core-1.3.jar" />
</classpath>

您需要向类路径添加更多内容:

  • 单元测试自己
  • 您尝试测试的代码(当它不在同一位置时)
  • 以上所需的任何罐子
  • 请注意,您可以引用在别处定义的路径,而不是复制所有内容:

    <path refid="tests.classpath"/>
    
    
    

    有关更多信息,请参阅上面我在问题中粘贴的错误,当运行ant build时,我得到了一个致命的漏洞,那就是找不到测试类本身。
    <classpath>
        <pathelement location="${p}/lib/junit.jar" />
        <pathelement location="${p}/lib/hamcrest-core-1.3.jar" />
    </classpath>
    
    <path refid="tests.classpath"/>