Hamlet D'Arcy has been writing software for over a decade, and has spent considerable time coding in C++, Java, and Groovy. He's passionate about learning new languages and different ways to think about problems, and recently he's been discovering the joys of both F# and Scheme. He's an active member of the Groovy Users of Minnesota and the Object Technology User Group, is a committer on the Groovy project, and is a contributor on a few open source projects (including JConch and the IDEA Groovy Plugin). He blogs regularly at http://hamletdarcy.blogspot.com and can be found on Twitter as HamletDRC (http://twitter.com/hamletdrc). Hamlet is a DZone MVB and is not an employee of DZone and has posted 28 posts at DZone. You can read more from them at their website. View Full User Profile

Mockito – Screencasts for Stubbing, Verifying, and Argument Matching

12.15.2010
| 7810 views |
  • submit to reddit

We're rolling out Mockito and trying to raise our testability at work and I'm set to give a presentation/training session tomorrow to a few new teams. In case you don't know, Mockito is a mock object framework for Java. It's competitors are EasyMock, JMock, and others if you're more familiar with those. If you haven't seen it then you may want to check out my old post "Mockito - Pros, Cons, and Best Practices". To prepare for my presentation I decided to record myself practicing my material and post it on youtube. Enjoy!

The first screencast is about creating mock objects and stubbing behavior. These are the absolute basics of mocking.


The second screencast is about verifying behavior, or verifying side effects, using Mockito. This is a little more advanced but still an essential API in working with Mockito. YouTube reports this video as 13 minutes long, but don't worry it is only 4:45. Some quirk of YouTube.


The final screencast is about argument matchers, which add flexibility to your stub and verify phases.


I hope you enjoyed these. They could be a little more practiced, but I'm happy enough with the quality. I recorded these on Ubuntu 10.4 using recordMyDesktop and mencode to convert from .ogv to .avi.

From http://hamletdarcy.blogspot.com/2010/12/mockito-screencasts-for-stubbing.html

Published at DZone with permission of Hamlet D'Arcy, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Loren Kratzke replied on Fri, 2010/12/17 - 3:27pm

Excellent series. Screencasts are not as easy to create as they are to consume. Good job.

I am curious what screencast software you used to create the series.

Maxim Zakharenkov replied on Mon, 2010/12/20 - 9:06am

Thanks for the post. Just one note, in the first screen cast the last one mock for the UserManager can be created like this:
UserManager userManager = new UserManager() {
	int count = 0;
	int getUserCount() { 
		return ++count 
	}
}
no Mock framework is needed at all and the code is much better readable! What I am afraid of is that when people start actively use Mock stuff, they sometimes may forget about some old native possibilities of Java.

Maurizio Cucchiara replied on Wed, 2010/12/22 - 4:21am in response to: Maxim Zakharenkov

@Maxim This only because UserManager is a simple class. Anyway, good job (except for the second video: you forgot to stop registration)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.