Last updated : 01/10/2002; 18:20:47

Joe's Jelly

Joe Walnes rambling on and on about Software Development, Java and Extreme Programming.

NAVIGATION >>

/WIKI /WEBLOG /THOUGHTWORKS /OPENSYMPHONY /EMAIL

:: ELSEWHERE
xp developer wiki
c2 xp wiki
the server side
javaworld
sd magazine
jakarta

:: BLOGS
Mike Cannon-Brookes
Graham Glass
Paul Hammant
Elliotte Rusty Harold
Darren Hobbs
Patrick Lightbody
Charles Miller
Brett Morgan
Rickard Öberg
Mike Roberts
Sam Ruby
Joel Spolsky
James Strachan
Clemens Vasters

:: INVOLVEMENTS
SiteMesh
QDox
MockDoclet
OSCore
OSUser
PropertySet
RichTags
Marathon
SiteMesh C++
Alt-RMI
Jelly MockTags
more...
:: BACKLOGS
September 2002
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Aug   Oct



Click here to visit the Radio UserLand website.

:. 16 September 2002

  9:07:20 AM  

Started contributing to the .Net MockObjects project this weekend. It's still in the early stages but the fundamentals are there. I can't take any credit for that, Griffin has gotten off to a great start. All I've really done so far is convert the unit tests to NUnit 2.0. Watch this space though. [Pushing the envelope]

Great! This is something high up on my 'I need one of those' list at the moment. I'll be watching this quite closely.

I was dabbling a bit with a mock library for .NET using the System.Reflection.Emit stuff based on the concepts used in EasyMock and Nat Pryces' Mock Library. The advantage the Emit stuff has over Java dynamic proxies is it can be used to generate any code in memory (not just interface implementations).

Something like:

public class Thing {
  public int DoSomething(string arg) {
    //..
  } 
}
public class UsesThing {
public int Go(Thing thing) {
    return thing.DoSomething("hello");
  }
}
public class UsesThingTest {
  [Test]
  public void CheckCorrectArgumentPassed() {
    // setup mock
    Mock mockThing = new Mock(typeof(Thing));
    mockThing.expectAndReturn("Go", 77, "hello");
   
// execute code to test
    UsesThing usesThing = new UsesThing();
    int result = usesThing.Go((Thing)mockThing.Value);
    // check results
    Assertion.AssertEquals(77, result);
    mockThing.verify();
  } 
}

Note that Mock is a generic class - internally it uses Emit stuff to extend Thing and override all the methods with mocked versions.

The only thing I'm stuck on is the fact that you cannot override methods that aren't marked as virtual.... hmmmm.......


Web-design by John Doe from open source web design.