Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <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> </blockquote> <p>The <em>"integration not unit"</em> is minor issue (especially when compared with <em>"test or not test"</em>), I wouldn't worry about that. There are other, more serious problems with this approach:</p> <ul> <li>Writing scripts. You'll most likely end up coding SQL by hand which requires a lot of discipline especially when model is complex. Typos are painful, it's hard to debug/detect problems, you need to take IDE/tools into consideration too.</li> <li>When your model changes, you'll be fixing those SQL scripts, which raises same issues - typos, hard to spot errors and so on, lack of IDE support.</li> </ul> <p>Overall, this approach is <strong>expensive in terms of maintainability</strong>.</p> <blockquote> <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> </blockquote> <p>Decent approach, you should investigate libraries that make this process easier (hint: <a href="https://github.com/AutoFixture" rel="nofollow"><strong>AutoFixture</strong></a>, <a href="http://code.google.com/p/nbuilder/" rel="nofollow"><strong>NBuilder</strong></a>).</p> <blockquote> <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> </blockquote> <p>Same issue as with build-scripts one - changes will be expensive.</p> <blockquote> <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> </blockquote> <p>This is essentially the same solution as your second one, but with XML as man in the middle. Why adding extra layer?</p> <blockquote> <p>UR DOIN IT RONG. The fact that your domain objects are so highly referential is the main problem. Simplify it.</p> </blockquote> <p>Rather unlikely. By their nature domain objects they tend to be complex.</p> <h2>Conclusion</h2> <p>There are no quick-and-dirty workarounds to such problem. Complex domain means there has to be some extra work done at some point. <em>Serialization-based</em> solutions (1, 3, 4), even though some may seem easy now, will only postpone said extra work to the moment when changes are introduced. In almost every case, I'd go with better <strong>flexibility</strong> and <strong>readiness for changes</strong> (which only second solution offers - if done properly).</p>
 

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