Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 07, 2007 dmocks version 0.1 | ||||
---|---|---|---|---|
| ||||
Hello all. For the Test-Driven Development people out there, and all the fans of unittesting, I'm releasing a mock objects framework for D2, dmocks. It can mock classes and interfaces, even if they are templated; it cannot mock structs due to inheritance issues, and it can only mock virtual methods (no templated methods, sorry; not my fault). Download: http://damask-mud.googlecode.com/files/dmocks.zip Subversion: svn checkout http://damask-mud.googlecode.com/svn/trunk/mocks/ Note that these are temporary locations, and I hope to move the project to dsource shortly. Examples: class Bar { int doSomeCalculations (ubyte[] data) { ... } } class Foo { private Bar bar; this (Bar bar) { this.bar = bar; } int calculateStuff (ubyte[] data) { int i = bar.doSomeCalculations (data); ... return i; } unittest { Mocker m = new Mocker(); auto bar = m.Mock!(Bar); ubyte[] data = null; bar.doSomeCalculations(data); m.LastCall().Return(5); // or m.Expect(bar.doSomeCalculations(data)).Return(5); m.Replay(); Foo target = new Foo(bar); target.calculateStuff(data); m.Verify(); } } Address any complaints you have to dhasenan -at- gmail -dot- com. If anyone has issues with style, I can offer both CamelCase and abridgedCamelCase; if enough people request it, I'll offer a free function interface if I can find a sane way of doing it. Complaints about functionality will be addressed first. The framework in its current state represents about three days' work, which is more a sign of the ease of using D than any special abilities I have. Dmocks is brought to you by __traits and string mixins. We therefore regret to inform you that it is only available for D version 2. |
November 07, 2007 Re: dmocks version 0.1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christopher Wright | For anyone who doesn't know what mock objects are and wants to, there's Wikipedia: http://en.wikipedia.org/wiki/Mock_object In brief, a mock object allows you to test how one class interacts with another, and test the functionality of each class independently of the rest. It does so by acting like an object that the class you are testing uses, but recording and checking which methods are called and returning values according to what the programmer explicitly told it to. Christopher Wright wrote: > Hello all. > > For the Test-Driven Development people out there, and all the fans of unittesting, I'm releasing a mock objects framework for D2, dmocks. It can mock classes and interfaces, even if they are templated; it cannot mock structs due to inheritance issues, and it can only mock virtual methods (no templated methods, sorry; not my fault). > > Download: > http://damask-mud.googlecode.com/files/dmocks.zip > > Subversion: > svn checkout http://damask-mud.googlecode.com/svn/trunk/mocks/ > > Note that these are temporary locations, and I hope to move the project to dsource shortly. > > Examples: > class Bar { > int doSomeCalculations (ubyte[] data) { ... } > } > class Foo { > private Bar bar; > this (Bar bar) { this.bar = bar; } > > int calculateStuff (ubyte[] data) { > int i = bar.doSomeCalculations (data); > ... > return i; > } > > unittest { > Mocker m = new Mocker(); > auto bar = m.Mock!(Bar); > ubyte[] data = null; > > bar.doSomeCalculations(data); > m.LastCall().Return(5); > // or m.Expect(bar.doSomeCalculations(data)).Return(5); > > m.Replay(); > Foo target = new Foo(bar); > target.calculateStuff(data); > > m.Verify(); > } > } > > Address any complaints you have to dhasenan -at- gmail -dot- com. If anyone has issues with style, I can offer both CamelCase and abridgedCamelCase; if enough people request it, I'll offer a free function interface if I can find a sane way of doing it. Complaints about functionality will be addressed first. > > > The framework in its current state represents about three days' work, which is more a sign of the ease of using D than any special abilities I have. > > Dmocks is brought to you by __traits and string mixins. We therefore regret to inform you that it is only available for D version 2. |
November 08, 2007 Re: dmocks version 0.1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christopher Wright | Christopher Wright wrote:
> For anyone who doesn't know what mock objects are and wants to, there's Wikipedia: http://en.wikipedia.org/wiki/Mock_object
You should add a link to your project on that page's "External links" section! All other languages seem to be already mentioned there.
L.
|
November 08, 2007 Re: dmocks version 0.1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Lionello Lunesu wrote:
> Christopher Wright wrote:
>> For anyone who doesn't know what mock objects are and wants to, there's Wikipedia: http://en.wikipedia.org/wiki/Mock_object
>
> You should add a link to your project on that page's "External links" section! All other languages seem to be already mentioned there.
>
> L.
I will, once Brad gets back to me and the project has a permanent home.
Though it seems like advertising, if I add the link to my project.
|
Copyright © 1999-2021 by the D Language Foundation