Note that there are some explanatory texts on larger screens.

plurals
  1. POSerialized object graphs for arranging unit tests
    primarykey
    data
    text
    <p>I have an application where the problem domain is represented by domain objects which are highly interrelated. I have split the domain into a few aggregate root objects which helps impose order on the model, however arranging preconditions for unit tests is arduous as creating instances of these aggregate roots requires creating a great number of supporting objects that are referenced.</p> <p>I want to write repeatable, isolated unit tests that exercise the application without the need for external dependencies (and ideally without writing a huge chunk of code).</p> <p>I think these are my options. Any preference, or other suggestions?</p> <ol> <li><p>Write build scripts that setup the project database and INSERT known data into it, against which unit tests are executed. This is my least favorite option as it introduces an external dependency (and therefore isn't a true unit test) as well as many more potential failures. It also doesn't isolate the business function being tested because the fault could lie within the data access code.</p></li> <li><p>Create re-usable factories that create domain objects with a known state, against which unit tests are run. This will work well, but means lots of boilerplate code to be written, and therefore lots to change when/if the model changes.</p></li> <li><p>(Current method) Create binary serializations of my aggregate root objects into files that are checked in with the test project. The unit tests deserialize them for their tests. The downside to this is that if the underlying type changes deserialization will fail and all the serialized files have to be re-created.</p></li> <li><p>Suck it up and write a custom serializer that serializes the graphs to XML files that can be checked in to the solution and deserialized at test time. Like 2, this means alot of up-front boilerplate code to be written, but maintenance is easier as the serialized state can be edited easily with a text editor if the model changes.</p></li> <li><p>UR DOIN IT RONG. The fact that your domain objects are so highly referential is the main problem. Simplify it.</p></li> </ol> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload