Configuration
All about XML Resources
All about Testing Strategies
Problems
To connect the xml resource to your testclass you must implement the abstract method initContext() in your extension of the DDTTestCase class. This method will be executed implicitely during execution preparation.
To facilitate usage there is another method provided my DDTTestCase. Here follows an example how to use the two methods in the default behavior.
... public void initContext(){ initTestData("MyClassResource", "MyClassId"); } ...
... public void initContext(){ initTestData("/my/own/path/to/MyClassResource.xml", "MyClassId"); } ...
... public void initContext(){ initTestData("MyClassId"); } ...
public void initContext(){ initTestData("MyClassId", "MyClassId"); }
Search will be done first on ClassPath then on filesystem.
You will find a properties file junitx.ddtunit.data.processing.TypeAbbreviator.properties. This file must be placed in the same package in the classpath as TypeAbbreviator.class. To modify it just place a copy into the classpath before searching in the jar. Now you can just add the types you need. - Or send a mail and if it is a class provided along with it will be added to the internal properties file.
Because it is rather tedious to write something like java.lang.String over and over again a special factory was introdused to the package junitx.ddtunit.data.processing The class TypeAbbreviator contains a dictionary to translate shortcut notatopns used for XML attribute type to the correct type notation. The defined details can be displayed to System.out by just executing this class as application.
Every xml resource should start with
<?xml version="1.0" ?> <ddtunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ddtunit.sourceforge.net/ddtunit.xsd"> <cluster id="ThisIdShouldBeAdapted"> ...
Thanks for the example code and actual question to Ted Velkoff.
The intention of the framework is to provide an environment to validate
asserts on a class or service/system contract.
Your investigation is focused on a class or service/system under test (CUT, SUT).
To do asserts on the behavior of this CUT, good or bad, you will feed it
with different parameters and check against expected results.
With this intention in mind you expect your parameters to be valid in the sense of
constructing these. Otherwise you wouldn't even start execution of the cut
=> no parameters, no run.
With this basic concept of operation expects all test parameters
provided in the xml resource to be constructable. This will be done before
actually executing any of the methods in the test class.
Now you have two choices to phrase the good case execution and a third for
exceptional behavior of the example test:
public void testConstructor() throws InvalidDateException { CompositeDate subject = new CompositeDate((Integer) getObject("day"), (Integer) getObject("month"), (Integer) getObject("year")); addObjectToAssert("expectedDay", subject.getDay()); addObjectToAssert("expectedMonth", subject.getMonth()); addObjectToAssert("expectedYear", subject.getYear()); }
<test id="test20060101"> <objs> <obj id="day" type="int">1</obj> <obj id="month" type="int">1</obj> <obj id="year" type="int">2006</obj> </objs> <asserts> <assert id="expectedDay" type="int" action="isEqual">1</assert> <assert id="expectedMonth" type="int" action="isEqual">1</assert> <assert id="expectedYear" type="int" action="isEqual">2006</assert> </asserts> </test>
public void testConstructor() throws InvalidDateException { CompositeDate subject = new CompositeDate((Integer) getObject("day"), (Integer) getObject("month"), (Integer) getObject("year")); addObjectToAssert("expectedCompositeDate", subject); }
<test id="test20000229"> <objs> <obj id="day" type="int">29</obj> <obj id="month" type="int">2</obj> <obj id="year" type="int">2000</obj> </objs> <asserts> <assert id="expectedCompositeDate" type="com.foo.model.calendar.CompositeDate" action="isEqual" hint="call"> <day>29</day> <month>2</month> <year>2000</year> </assert> </asserts> </test>
public void testConstructorException() throws InvalidDateException { CompositeDate subject = new CompositeDate((Integer) getObject("day"), (Integer) getObject("month"), (Integer) getObject("year")); }
<test id="test20060431"> <objs> <obj id="day" type="int">31</obj> <obj id="month" type="int">4</obj> <obj id="year" type="int">2006</obj> </objs> <asserts> <exception id="expected" type="com.foo.model.calendar.InvalidDateException" action="isInstanceOf" /> </asserts> </test>