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

StackOverflow https://stackoverflow.com/questions/21148503

  •  28-09-2022
  •  | 
  •  

質問

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(); }
  ...
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top