dhasenan
Joined: 03 Feb 2005 Posts: 73 Location: New York
|
Posted: Fri Mar 21, 2008 12:57 pm Post subject: Up and coming: selfmock |
|
|
Dmocks is unfortunately hampered by problems with dmd2's stability. However, that's a problem only with automatically generating a mock class automatically. Granted, it's a lot more painful to do that by hand, but it's at least possible. And it doesn't depend on getting around ugly compiler bugs nearly as much.
So, I'm cannibalizing dmocks to create selfmock. It'll support dmd1 and Tango, and it'll require you to create each mocked class manually. This should be mostly painless; in the general case, it should look a bit like this:
Code: |
class MockMyInterface : Mocked, IMyInterface
{
mixin(method!(&IMyInterface.method1));
mixin(method!(&IMyInterface.method2));
}
class MyTests : TestFixture
{
private static IMyInterface _myInterface;
private static Mocker _mocks;
override void setup()
{
_myInterface = new MockMyInterface();
_mocks = new Mocker();
_mocks.register(_myInterface);
}
// ...
}
|
If you're using interfaces, it should roughly double the amount of work you do in extracting an interface. Annoying, but better than nothing. There are the typical issues with overloaded methods, of course.
Once dmd2 is stable and supports Tango, it'll be a relatively minor matter for me to add support for automocking and for client code to convert to it. |
|