Home Tutorials Javatesting JUnit Test 'assertTrue' Example Using Ant
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JUnit Test 'assertTrue' Example Using Ant

Advertisement
This example illustrates about how to use the 'assertTrue' assertion method to test whether the class file executed test cases successfully or not.

JUnit Test 'assertTrue' Example Using Ant

     

This example illustrates about how to use the 'assertTrue' assertion method to test whether the class file executed test cases successfully or not. In case of  if, test case execute success for specific class then it return true but if test case not execute properly the it return false and throw a Test Failure method. 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" />
  <property name="TALK" value="true" />
  
  <path id="classpath.base"/>
  <path id="classpath.test">
  <pathelement location="${testdir}" />
  <path refid="classpath.base" />
  </path>

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

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

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

</project>

Source Code of JUnitTestExample.java

import junit.framework.*;

public class JUnitTestExample extends TestCase{

  public void test(){
  assertTrue( "JUnitTestExample"true );
  }
}

Output

Without using of <property name="TALK" value ="true"/> the following output will be display

Download Source Code

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 27, 2008

Related Tutorials

Ask Questions?    Discuss: JUnit Test 'assertTrue' Example Using Ant  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com