More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JUnit Test 'assertSame' Example Using Ant 
 

This example illustrates about how to use the 'assertSame' assertion method.

 

JUnit Test 'assertSame' Example Using Ant

                         

This example illustrates about how to use the 'assertSame' assertion method. The method is used to compare between two variable whether both are same or not, if both expected and actual are not same then the AssertionError Exception throw the following error:

[junit] Testsuite: AssertSameExample
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.031 sec
[junit]
[junit] Testcase: test(AssertSameExample): FAILED
[junit] not equal expected same:<2> was not:<4>
[junit] junit.framework.AssertionFailedError: not equal expected same:<2> was not:<4>
[junit] at AssertSameExample.test(Unknown Source)
[junit]
[junit]
[junit] Test AssertSameExample FAILED

but if both are same then the program executed test case successfully. In this example build.xml file is used to compile, test and run the java file. The <property name="TALK" value ="true"/> is used to search path for source files, search path for class files, parsing the jar file, loading the all required classes and checking the class file. If  <property name="TALK" value ="true"/> is not used in build.xml file then the output displays only  [junit] Testsuite

build.xml

<project name="JUnitTest" default="test" basedir=".">

  <property name="testdir" location="test" />
    
  <path id="classpath.base"/>
  <path id="classpath.test">
    <pathelement location="${testdir}" />
    <path refid="classpath.base" />
  </path>

  <target name="clean" >
    <delete>
      <fileset dir="${testdir}" includes="**/*.class" />
    </delete>
  </target>

  <target name="compile" depends="clean">
    <javac srcdir="${testdir}" >
      <classpath refid="classpath.test"/>
    </javac>
  </target>

  <target name="test" depends="compile">
    <junit>
      <classpath refid="classpath.test" />
      <formatter type="brief" usefile="false" />
      <test name="AssertSameExample/>
    </junit>
  </target>

</project>

Source code of AssertSameExample.java

 

import junit.framework.*;

public class AssertSameExample extends TestCase{

  public void test(){
    int expected = 4;
    int actual = 2;
    try{
      assertSame("not equal", expected, actual);
    }catch(AssertionError exception){ }
  }
}

output:

 

Download Source Code

                         

» View all related tutorials
Related Tags: c http ide interface application io lua user graph test users vi value eval lock using int this id block

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.