Thursday, April 7, 2011

Getting started with JUnit and Eclipse

Over the years I've done load testing and user acceptance testing but this is the first time I've done any serious unit testing. I'm be using JUnit 4.x and trying my best to stick test-driven development.

Everyone learns in different ways, some are book-learners and others like to dive right in and get their hands dirty.  I'd like to think I take a hybrid approach but I'm always thankful for a nice tutorial.  I definitely recommend the Eclipse and Java for Total Beginners video tutorial.  Sure it's geared for true Java and Eclipse beginners but it covers JUnit and test-driven development in some clear and concise detail.

The tutorial doesn't include using Ant to run your JUnit tests.  Here's the code I am currently using in my Ant build.xml for invoking the JUnit tests in my project.

<target name="junit" depends="compile, jar">
    <junit showOutput="true" printsummary="on" fork="true" haltonfailure="true" dir="${basedir}">
        <classpath refid="project.classpath" />
        <formatter type="xml" />
        <batchtest todir="${output.dir}">
            <fileset dir="${test.dir}">
                <include name="**/*Test*.java" />
            </fileset>
        </batchtest>
    </junit>
</target>

No comments:

Post a Comment