[sword-devel] unti test classes for JSword

Bobby Nations sword-devel@crosswire.org
13 Jan 2002 05:26:35 -0600


--=-sRED7vxANzWaYMiYRo3F
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

All,

I've made some progress on getting the unit test classes up and going on
the JSword project.  Attached are two test classes along with a new ant
build containing targets to run all test cases and generate reports on
their results.  The target names are 'test' and 'results' respectively. 
In order to run the results target, you'll need two jar files from the
apache group's xalan xml project, xalan.jar and xerces.jar, to be either
in your CLASSPATH or in the ANT_HOME/lib directory.  I'm working with
them to get this requirement removed.

Cheers,

Bobby

P.S. Is anyone else working on JSword?



--=-sRED7vxANzWaYMiYRo3F
Content-Disposition: attachment; filename=build.xml
Content-Transfer-Encoding: quoted-printable
Content-Type: text/xml; charset=ISO-8859-1

<?xml version=3D"1.0" encoding=3D"iso-8859-1"?>
<project name=3D"jsword" default=3D"jar" basedir=3D".">

    <!-- Set the project wide classpath -->
    <path id=3D"project.classpath">
        <pathelement path=3D"${java.class.path}/"/>
        <pathelement location=3D"./"/>
        <fileset dir=3D"lib">
            <include name=3D"**/*.jar"/>
        </fileset>
    </path>

    <target name=3D"init">
        <tstamp/>
	<property name=3D"build.compiler" value=3D"modern" />
	<property name=3D"src.dir" value=3D"src" />
	<property name=3D"build.dir" value=3D"btree" />
	<property name=3D"build.test.dir" value=3D"${build.dir}/tests" />
	<property name=3D"dist.dir" value=3D"dist" />
	<property name=3D"reports.dir" value=3D"${dist.dir}/reports" />
	<property name=3D"reports.results.dir" value=3D"${reports.dir}/results" />
	<property name=3D"javadoc.dir" value=3D"${dist.dir}/api" />
    </target>

    <target name=3D"prepare" depends=3D"init">
        <mkdir dir=3D"${build.dir}"/>
	<mkdir dir=3D"${build.test.dir}" />
        <mkdir dir=3D"${dist.dir}"/>
        <mkdir dir=3D"${reports.dir}"/>
        <mkdir dir=3D"${reports.results.dir}"/>
        <mkdir dir=3D"${javadoc.dir}"/>
    </target>

    <target name=3D"compile" depends=3D"prepare">
        <javac srcdir=3D"${src.dir}"
            destdir=3D"${build.dir}" optimize=3D"on"
            excludes=3D"**/DisplayConf.java"
            deprecation=3D"on"
            classpathref=3D"project.classpath"/>
    </target>

    <target name=3D"jar" depends=3D"compile">
        <jar jarfile=3D"${dist.dir}/sword.jar" basedir=3D"${build.dir}"/>
    </target>

    <target name=3D"test" depends=3D"compile">
        <junit printsummary=3D"on" fork=3D"on">
            <classpath>
                <pathelement location=3D"${build.dir}" />
            </classpath>
            <formatter type=3D"xml"/>
            <batchtest todir=3D"${build.test.dir}" >
                <fileset dir=3D"${build.dir}">
                    <include name=3D"**/*Test.class"/>
                </fileset>
            </batchtest>
        </junit>
    </target>

    <target name=3D"results" depends=3D"test">
        <junitreport todir=3D"${reports.results.dir}" >
            <fileset dir=3D"${build.test.dir}">
                <include name=3D"TEST-*.xml"/>
            </fileset>
            <report format=3D"frames" todir=3D"${reports.results.dir}" />
        </junitreport>
        <echo message=3D"Complete results can be found at" />
        <echo message=3D"${reports.results.dir}" />
    </target>

    <target name=3D"javadoc" depends=3D"prepare">
        <javadoc destdir=3D"${javadoc.dir}"
	         sourcepath=3D"${src.dir}/"
                 private=3D"true"
		 packagenames=3D"SwordMod, org.crosswire.*">
            <classpath refid=3D"project.classpath"/>
        </javadoc>
    </target>

    <target name=3D"modedit" depends=3D"prepare">
        <javac srcdir=3D"apps/ModEdit/${src.dir}"
               destdir=3D"${build.dir}" optimize=3D"on"
               classpathref=3D"project.classpath"/>
    </target>

    <target name=3D"clean" depends=3D"init">
        <delete dir=3D"${build.dir}"/>
        <delete dir=3D"${dist.dir}"/>
    </target>

</project>    =20
    =20

--=-sRED7vxANzWaYMiYRo3F
Content-Disposition: attachment; filename=CanonTest.java
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c++; charset=ISO-8859-1

// CanonTest.java

package org.crosswire.sword.keys;

import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * CanonTest    (Copyright 2001 <company>)
 *=20
 * <p> This class performs unit tests on org.crosswire.sword.keys.Canon </p=
>
 *=20
 * @author Bobby Nations <bobby@bobbynations.com>
 * @date $Date: $
 * @version $Revision: $
 *=20
 * @see org.crosswire.sword.keys.Canon
 * @see some.other.package
 */

public class CanonTest extends TestCase
{
    /**
     * Constructor (needed for JTest)
     * @param name    Name of Object
     */
    public CanonTest(String name) {
        super(name);
    }

    /**
     * Used by JUnit (called before each test method)
     */
    protected void setUp() {
        canon =3D new Canon();
    }

    /**
     * Used by JUnit (called after each test method)
     */
    protected void tearDown() {
        canon =3D null;
    }

    /**
     * Test the constructor: Canon()
     */
    public void testCanon() {
    }

    /**
     * Test the old testament books array #1
     */
    public void testOTBooks1() {
        assertTrue( "Genesis" =3D=3D canon.otbooks[0].name );
        assertTrue( 50 =3D=3D canon.otbooks[0].chapmax );
    }

    /**
     * Test the old testament books array #2
     */
    public void testOTBooks2() {
        assertTrue( "Psalms" =3D=3D canon.otbooks[18].name );
        assertTrue( 150 =3D=3D canon.otbooks[18].chapmax );
    }

    /**
     * Test the old testament books array #3
     */
    public void testOTBooks3() {
        assertTrue( "Malachi" =3D=3D canon.otbooks[38].name );
        assertTrue( 4 =3D=3D canon.otbooks[38].chapmax );
    }

    /**
     * Test the new testament books array length
     */
    public void testOTBooksLength() {
        assertTrue( 39  =3D=3D canon.otbooks.length );
    }

    /**
     * Test the new testament books array #1
     */
    public void testNTBooks1() {
        assertTrue( "Matthew" =3D=3D canon.ntbooks[0].name );
        assertTrue( 28 =3D=3D canon.ntbooks[0].chapmax );
    }

    /**
     * Test the new testament books array #2
     */
    public void testNTBooks2() {
        assertTrue( "Titus" =3D=3D canon.ntbooks[16].name );
        assertTrue( 3 =3D=3D canon.ntbooks[16].chapmax );
    }

    /**
     * Test the new testament books array #3
     */
    public void testNTBooks3() {
        assertTrue( "Revelation of John" =3D=3D canon.ntbooks[26].name );
        assertTrue( 22 =3D=3D canon.ntbooks[26].chapmax );
    }

    /**
     * Test the new testament books array length
     */
    public void testNTBooksLength() {
        assertTrue( 27  =3D=3D canon.ntbooks.length );
    }

    /**
     * Test the abbreviations for all books array #1
     */
    public void testAbbrevs1() {
        assertTrue( "1 C" =3D=3D canon.builtin_abbrevs[0].ab );
        assertTrue( 46 =3D=3D canon.builtin_abbrevs[0].book );
    }

    /**
     * Test the abbreviations for all books array #2
     */
    public void testAbbrevs2() {
        assertTrue( "PSALMS" =3D=3D canon.builtin_abbrevs[170].ab );
        assertTrue( 19 =3D=3D canon.builtin_abbrevs[170].book );
    }

    /**
     * Test the abbreviations for all books array #3
     */
    public void testAbbrevs3() {
        int n =3D  canon.builtin_abbrevs.length;
        assertTrue( "" =3D=3D canon.builtin_abbrevs[n-1].ab );
        assertTrue( -1 =3D=3D canon.builtin_abbrevs[n-1].book );
    }

    /**
     * Test the abbreviations for all books array #4
     */
    public void testAbbrevsLength() {
        assertTrue( 184  =3D=3D canon.builtin_abbrevs.length );
    }


    /**
     * Main method needed to make a self runnable class
     *=20
     * @param args This is required for main method
     */
    public static void main(String[] args) {
        junit.textui.TestRunner.run( new TestSuite(CanonTest.class) );
    }

    private Canon canon;
}

--=-sRED7vxANzWaYMiYRo3F
Content-Disposition: attachment; filename=SWKeyTest.java
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c++; charset=ISO-8859-1

// SWKeyTest.java

package org.crosswire.sword.keys;

import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * SWKeyTest    (Copyright 2001 <company>)
 *=20
 * <p> This class performs unit tests on org.crosswire.sword.keys.SWKey </p=
>
 *=20
 * <p> Explanation about the tested class and its responsibilities </p>
 *=20
 * <p> Relations:
 *     SWKey extends java.lang.Object <br>
 *     SWKey implements java.lang.Cloneable, java.lang.Comparable </p>
 *=20
 * @author <Your Name> <e-mail> - <company>
 * @date $Date: $
 * @version $Revision: $
 *=20
 * @see org.crosswire.sword.keys.SWKey
 * @see some.other.package
 */

public class SWKeyTest extends TestCase
{

  /**
   * Constructor (needed for JTest)
   * @param name    Name of Object
   */
  public SWKeyTest(String name) {
    super(name);
  }

  /**
   * Used by JUnit (called before each test method)
   */
  protected void setUp() {
    //swkey =3D new SWKey();
  }

  /**
   * Used by JUnit (called after each test method)
   */
  protected void tearDown() {
    swkey =3D null;
  }

  /**
   * Test the constructor: SWKey()
   */
  public void testSWKey() {

  }

  /**
   * Test the constructor: SWKey(String)
   */
  public void testSWKey_1() {
    //Must test for the following parameters!
    String str [] =3D {null, "\u0000", " "};

  }

  /**
   * Test the constructor: SWKey(SWKey)
   */
  public void testSWKey_2() {
    //Must test for the following parameters!
    //SWKey;

  }

  /**
   * Test method: int compareTo(Object)
   */
  public void testCompareTo() {
    //Must test for the following parameters!
    Object oValues [] =3D { null };

  }

  /**
   * Test method: java.lang.Object clone()
   */
  public void testClone() {

  }

  /**
   * Test method: String toString()
   */
  public void testToString() {

  }

  /**
   * Test method: void set(SWKey)
   */
  public void testSet() {
    //Must test for the following parameters!
    //SWKey;

  }

  /**
   * Test method: void next(int)
   */
  public void testNext_1() {
    //Must test for the following parameters!
    int intValues [] =3D {-1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE};

  }

  /**
   * Test method: void next()
   */
  public void testNext() {

  }

  /**
   * Test method: void previous(int)
   */
  public void testPrevious_1() {
    //Must test for the following parameters!
    int intValues [] =3D {-1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE};

  }

  /**
   * Test method: void previous()
   */
  public void testPrevious() {

  }

  /**
   * Test method: String getText()
   */
  public void testGetText() {

  }

  /**
   * Test method: int getError()
   */
  public void testGetError() {

  }

  /**
   * Test method: void position(int)
   */
  public void testPosition() {
    //Must test for the following parameters!
    int intValues [] =3D {-1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE};

  }

  /**
   * Test method: boolean isPersist()
   */
  public void testIsPersist() {

  }

  /**
   * Test method: void setPersist(boolean)
   */
  public void testSetPersist() {
    //Must test for the following parameters!
    boolean BValues [] =3D { true, false };

  }

  /**
   * Test method: boolean traversable()
   */
  public void testTraversable() {

  }

  /**
   * Test method: void setText(String)
   */
  public void testSetText() {
    //Must test for the following parameters!
    String str [] =3D {null, "\u0000", " "};

  }

  /**
   * Main method needed to make a self runnable class
   *=20
   * @param args This is required for main method
   */
  public static void main(String[] args) {
    junit.textui.TestRunner.run( new TestSuite(SWKeyTest.class) );
  }
  private SWKey swkey;
}

--=-sRED7vxANzWaYMiYRo3F--