Defining Objects By Default Constructor and Field Definitions

<objs><obj id="myId" type="my.class.Type" hint="fields">...</obj><objs>

To define value objects by field names you need to know the internal naming of the fields you want to populate. For mapping Java reflection is used. The access on private and protected fields is done using JUnit-Addons PrivateAccessor. - Implementation details might be subject to change.
Here follows an example:

...
  <test id="myFirstTestCase">
   <objs>
    <obj id="myObj" type="junitx.ddtunit.resources.SimpleVO">
      <doubleValue>12.4</doubleValue>
      <integerValue>4711</integerValue>
      <stringValue>My Text</stringValue>
    </obj>
   </objs>
  </test>
...
Object myObj reflects the Java object definition
public class SimpleVO {
    private Integer integerValue;
    private String stringValue;
    private Double doubleValue;

    /**
     * Default constructor.
     */
    public SimpleVO() {
        // no special initialization neccessary
    }
...

If you are using an empty object description

    <obj id="myObj" type="junitx.ddtunit.resources.SimpleVO" />
you will get the spcified object as long as the default constructor is accessible (public).

To specify a "null" assignment use the explizit description

    <obj id="myObj" type="junitx.ddtunit.resources.SimpleVO">!NULL!<obj>
sf logo