简体   繁体   中英

Using ArrayFixture with a list of objects containing nested non-primitive objects

I am using ArrayFixture to verify lists of non-primitive objects that contain other non-primitives. I have a simple setup like this:

public class Car {
  public String getName();
  public Details getDetails();
  ...
}

public class Details {
  public String getMake();
  ...
}

With ArrayFixture, all you need to do is call setActualCollection(yourListOfObjects) in the constructor of the class.

How do I reference the elements in the object's non-primitive variables? This is how my Fitnesse test looks:

|Verify Cars|
|name   | details Make | ... |
|Taurus | Ford         | ... |
|...    | ...          | ... | 

I have been able to easily use the ArrayFixture when the object in the list contains primitive objects, but I haven't found any documentation on how to handle non-primitive elements.

ArrayFixture uses the column headings as method names to execute on the objects in your collection, so you'd need methods on Car to access the details you want to check:

public class Car {
  public String getMake() { return getDetails().getMake(); }
  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM