Mockito Example (Java Mocking Framework) 122

Posted by Brett Schuchert Wed, 27 May 2009 05:15:00 GMT

Recently I was lamenting how much I liked Moq for C# and its API. I like that is uses lambdas and generics and I think both the interface and general approach are great.

Someone I follow on twitter, @tieTYT, suggested that I should give Mockito a try. It is a mocking library for Java, written by Szczepan Faber and friends.

Well I gave it a try and I found it to be an excellent Mocking framework similar in spirit to Moq and it worked well while not requiring lambdas.

I was in a mood, so I went ahead and wrote a quick tutorial. While it is still under construction, you can have a look at it. If you work through it, you’ll:
  • Develop something using TDD.
  • Using a mockist approach
  • Use Inversion of Control
  • Refactor code to use the GoF state pattern
  • Refactor code to use the GoF Template Method Pattern
  • Fix the code to avoid violation of the Liskov substitution principle (this is in there though not currently emphasized)
  • Fix the code to avoid violation of the Dependency Inversion Principle.
  • And as a side benefit, by using a TDD approach you’ll naturally avoid violating the Law of Demeter (though you will introduce some feature envy).

Have fun and please comment. You can also view a printable version.

FWIW, I learned Mockito and wrote this tutorial in about a single work day, so it was pretty easy to pick up and use. I suspect my recent experience with Moq gave me the mental model and then it was just a matter of syntax.

FitNesse Scenario Tables 74

Posted by Brett Schuchert Fri, 10 Apr 2009 07:21:00 GMT

This is a slightly rougher draft that the previous tutorials. Bob and I have talked about writing a new FitNesse book and these tutorials are practice for one part of the book. By the time these examples make it into a book, they will be the 3rd or 4th major revision.

In any case, here’s a tutorial that picks up where Script tables left off: http://schuchert.wikispaces.com/FitNesse.Tutorials.ScenarioTables.

I’ll be updating it over the weekend and into next week. I also hope to get the table table example done so I’ll have a complete set. If you are chomping at the bits for a table table example, let me know.

If you have comments about any of the tutorials or a wish list of what you’d like to see in a book related to acceptance testing with FitNesse, please post a comment or email me directly. shoe at objectmentor dot com.

FitNesse Decision Tables, a Tutorial 126

Posted by Brett Schuchert Tue, 31 Mar 2009 18:50:00 GMT

There’s a new tutorial on using FitNesse decision tables: http://schuchert.wikispaces.com/FitNesse.Tutorials.1.

This tutorial is a lead-up into using Query tables (that’s the next one I’ll be writing), which will describe some code you can get from github that will turn an object/collection into a well-formed query result.

These tutorials are background for a presentation I gave at SD West 2009 and will probably be giving at Agile 2009.

Comments Welcome.

FitNesse.Slim Scenario Shenanigans 69

Posted by Brett Schuchert Tue, 17 Mar 2009 04:25:00 GMT

I was working with Uncle Bob today and we came across a case where we wanted to invoke a curried method, but it was in FitNesse. It took me a while to grok it. Now I do, but it took some time.

On the surface it involves a Decision Table using a Scenario Table, which uses a Scenario Table that ultimately uses a named Fixture. It’s a bit of a long read but the results do suggest a way to express a generic test and then invoke it while reducing duplicated information.

Here’s the link: http://schuchert.wikispaces.com/FitNesse.Tutorials.ScenarioTables

This is a rough draft. I’ll be updating it over the next few days. If something does not make sense, please post a comment and I’ll update it.

For C# users: I have not tried this example using Slim.Net. It should work if you follow the instructions from the previous tutorial and simply replace the Java code with C# (not really a big deal when you see the code). In fact, C# offers a more flexible switch, so it would be a bit cleaner.

Getting Started with FitNesse in C# 97

Posted by Brett Schuchert Fri, 13 Mar 2009 06:45:00 GMT

The tutorial I mentioned yesterday now has a Java path and a C# path. Check out http://schuchert.wikispaces.com/FitNesse.Tutorials.0.

In addition, you’ll need to get Slim.net. Check out here: http://schuchert.wikispaces.com/Acceptance+Testing.UsingSlimDotNetInFitNesse.

Getting Started with FitNesse 59

Posted by Brett Schuchert Thu, 12 Mar 2009 06:29:00 GMT

Want to know the very basics of getting a first FitNesse example up and running? Check it out here: http://schuchert.wikispaces.com/FitNesse.Tutorials.0.

This is really bare-bones basic. I’ll be adding more tutorials (mostly by request).

Please place requests in the comments if you’d like to see other subjects (e.g. same thing with .Net and C#).

I’ll be sticking to Slim-based implementations unless there’s many requests for Fit.

ANN: OOPSLA Tutorial on "Principles of Aspect-Oriented Design in Java and AspectJ" 21

Posted by Dean Wampler Thu, 13 Sep 2007 16:34:29 GMT

I’m doing a tutorial on aspect-oriented design principles with examples in Java and AspectJ at OOPSLA this year (October 21st). You can find a description here. I believe Friday, 9/14, is the last day for early, discounted registration, so sign up now!

A short presentation on the same subject can be found here.