Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:03:41+00:00 2026-06-15T05:03:41+00:00

Junit report does not generate report if there is assertion error Class to be

  • 0

Junit report does not generate report if there is assertion error
Class to be tested

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;
    }
}

Junit Test class

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));
  }

}

I am using junit reporting to generate reports

The problem is if assertion fails the reports are not generate , the Ant Build fails . MY assumption is the if a assertion fails it should be listed in failures rather then error in Build result.

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>

MY requirement is if assertion fails it should show in failure ? What do i need to do ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:03:43+00:00Added an answer on June 15, 2026 at 5:03 am

    This question has been answered by Tharani in the comments… Answering it to make it from unanswered…

    Change the value of haltonfailure=”no” it will work as expedted …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

junit.framework.AssertionFailedError: Class com.android.deviceintelligence.test.Testshutdown has no public constructor TestCase(String name) or TestCase() at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at
I would like to generate a junit, nunit or mstest report for my QUnit
I have a JUnit Report who generate me a html report. My JUnit Report
Is there a way to customise the failure report from junit such that I
Getting follwing error when I run junit test case report through ant srcipt: Cannot
Is there any way that i need not write junit test cases and it
with ant it is possible to run JUnit tests and generate test reports in
Using JUnit 4.10 here is my test. package geometry; import org.junit.Assert.*; import org.junit.Test; public
I am new to junit testing and I have the following test - public
i am trying to get a coverage report for my android junit test project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.