2012-06-08 25 views
5

Junit báo cáo không tạo ra báo cáo nếu có lỗi khẳng định Class để được kiểm traJunit không tạo báo cáo nếu có lỗi khẳng định

public class Math { 

    static public int add(int a, int b) { 

     return a + b; 
    } 

    static public int multiply (int a, int b) { 
     if(a==0&&b==0) 
      return 0;; 
     return a * b; 
    } 
} 

lớp Junit thử nghiệm

import junit.framework.*; 

public class TestMath extends TestCase { 

    protected void setUp() { 

    // put common setup code in here 
    } 

    protected void tearDown() { 

    // put common cleanup code in here 
    } 

    public void testAdd() { 
    int num1 = 3; 
    int num2 = 2; 
    int total = 5; 
    int sum = 0; 
    sum = Math.add(num1, num2); 
    assertEquals(sum, total); 
    } 

    public void testMulitply() { 

    int num1 = 3; 
    int num2 = 7; 
    int total = 21; 
    int sum = 0; 
    sum = Math.multiply(num1, num2); 
    assertEquals("Problem with multiply", sum, total); 


    num1 = 5; 
    num2 = 4; 
    total = 20; 
    sum = Math.multiply(num1, num2); 
    assertEquals("Problem with multiply", sum, total); 

    } 
    public void testv(){ 
    Assert.assertEquals(1, Math.multiply(0, 0)); 
    } 

} 

Tôi đang sử dụng junit báo cáo để tạo các báo cáo

Vấn đề là nếu xác nhận không thành công các báo cáo không được tạo, Ant Build không thành công. Giả định của tôi là nếu một khẳng định không thành công nó sẽ được liệt kê trong thất bại thay vì sau đó lỗi trong kết quả xây dựng.

Ant XML

<project name="SampleJUnitTests" default="dist" basedir="."> 
    <description> 
     Sample JUnit Tests 
    </description> 
    <!-- set global properties for this build --> 

    <property name="project_name" value="junitSamples"/> 
    <property name="src" location="src"/> 
    <property name="build" location="bin"/> 
    <property name="dist" location="dist"/> 
    <property name="lib" location="lib"/> 
    <property name="res" location="res"/> 
    <property name="reports" location="reports"/> 

    <!-- the names of various distributable files --> 
    <property name="jar_name" value="${project_name}.jar"/> 
    <property name="war_name" value="${project_name}.war"/> 

    <!-- top level targets --> 

    <target name="compile" depends="init" description="compile the source code " > 
     <javac srcdir="${src}" destdir="${build}"> 
      <classpath> 
       <fileset dir="lib"> 
        <include name="**/*.jar"/> 
       </fileset> 
      </classpath> 
     </javac> 

    </target> 

    <target name="dist" depends="compile" description="generate the distributable files " > 

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> 
    <jar jarfile="${dist}/${jar_name}" basedir="${build}"/> 

    </target> 

    <target name="clean" 
     description="clean up" > 
    <!-- Delete the ${build} and ${dist} directory trees --> 
    <delete dir="${build}"/> 
    <delete dir="${dist}"/> 
    <delete dir="${reports}"/> 
    </target> 

    <target name="run-tests" depends="compile" description="run your test suite" > 
     <junit printsummary="yes" haltonfailure="yes" showoutput="yes" > 
      <classpath> 
       <pathelement path="${build}"/> 
       <fileset dir="lib"> 
        <include name="**/*.jar"/> 
       </fileset> 
      </classpath>    

      <batchtest fork="yes" todir="${reports}/raw/"> 
      <formatter type="xml"/> 
      <fileset dir="${src}"> 
       <include name="**/*Test*.java"/> 
      </fileset> 
      </batchtest> 
     </junit>  
    </target> 

    <target name ="test" depends="run-tests"> 
     <junitreport todir="${reports}"> 
      <fileset dir="${reports}/raw/"> 
      <include name="TEST-*.xml"/> 
      </fileset> 
      <report format="frames" todir="${reports}/html/"/> 
     </junitreport> 
    </target> 

    <target name ="run" depends="" description="if this project can be run, run it" > 

    </target> 

    <!-- supporting targets --> 

    <target name="init" description="initialize the build environment" > 
    <!-- Create the time stamp --> 
    <tstamp/> 
    <!-- Create directory structures --> 
    <mkdir dir="${build}"/> 
    <mkdir dir="${lib}"/> 
    <mkdir dir="${dist}/lib"/> 
    <mkdir dir="${reports}"/> 
    <mkdir dir="${reports}/raw/"/> 
    <mkdir dir="${reports}/html/"/> 
    </target> 

    <target name="all" depends="clean, test"> 

    </target> 

</project> 

yêu cầu của tôi là nếu khẳng định thất bại nó sẽ hiển thị trong thất bại? Tôi cần phải làm gì ?

+0

Đây có phải là nhật thực hay một vấn đề về kiến? Vui lòng gắn thẻ cho phù hợp. – oers

+1

Bạn có đang sử dụng [nhiệm vụ Ant JUnit không?] (Http://ant.apache.org/manual/Tasks/junit.html) Nếu vậy, vui lòng thêm một phần vào câu hỏi của bạn hiển thị XML chính xác mà bạn đang sử dụng. –

+0

@ChadNouis tôi đã thêm kiến ​​trúc XML Ant .Thanks for the response. –

Trả lời

2

Câu hỏi này đã được trả lời bởi Tharani trong các ý kiến ​​... Trả lời nó để làm cho nó từ chưa được trả lời ...

Thay đổi giá trị của haltonfailure = "no" nó sẽ làm việc như expedted ...

Các vấn đề liên quan