I am just starting in with the D2 programming language. I love the fact that unit testing is part of the language itself but I can't seem to find any mock object libraries for it. Is there a standard one out there?
Join Stack Overflow to learn, share knowledge, and build your career.
|
The only mock object library I know of is DMocks, but it is abandoned. It may not compile with recent compiler versions. Maybe BlackHole, WhiteHole and AutoImplement from std.typecons will help you to some extent. |
||||
|
|
|
||||
|
|
|
While it's not as fancy as a real mock object library could be, I currently do dependency injection with good results the following way:
If no MockEngine is supplied Car defaults to using the preferred AtomicEngine which is neat because that's what I want most of the time. Also note that the injection is done at compile-time with no run-time penalty for the mocking capabilities, i.e. no inheritance is required.
Let's test the car with a broken engine like this. |
|||||
|
|
I'm the author of DUnit which contains a mocking solution. It's used like this:
The reference is here: http://htmlpreview.github.io/?https://github.com/nomad-software/dunit/master/docs/dunit/mockable.html A bigger example is here: https://github.com/nomad-software/dunit/blob/master/source/example.d |
|||
|
|