Showing posts with label mockito. Show all posts
Showing posts with label mockito. Show all posts

Wednesday, March 24, 2010

Eclipse and Mockito

Mockito is great. A big part of it is the syntactic sugar, which relies on using static imports. Eclipse, by default, removes static imports when you use 'Organize Imports' (Ctrl+Shift+O). This saddened me, so I found a way to fix it. Thanks go to this post on static import content assist and the post it links on organize imports. I will repeat both instructions in here in one place.

Part 1: Tell Eclipse Not To Remove My Precious Static Imports
  1. Open Preferences (Window-> Preferences)
  2. Browse to Java -> Code Style -> Organize Imports
  3. Change 'Number of static imports needed for .* to '1' 
  4. Click Ok 
Part 2: Get Eclipse to Create the Mockito Static Import for Me
  1. Open Preferences (Window -> Preferences)
  2. Browse to Java -> Editor -> Content Assist -> Favorites
  3. Click 'New Type...'
  4. Enter org.mockito.Mockito
  5. Click Ok twice. 
Now you can write unit tests with Mockito in Eclipse without issues. You can now type mock and ctrl+space and Eclipse will add the static import for you. It will also leave it alone when you Organize Imports going forward. No more trying to remember not to Ctrl+Shift+O when editing a mockito test.

Thursday, November 5, 2009

Szczepan Faber is my bartender

I've known about Mockito for a little while, but I've only just now officially tried it today, and Sczepan Faber (and friends) are now my bartenders, and when it comes to mocking, a nice cold mockito is my new drink of choice.

Wow. Seriously, wow.

The syntax is exceptionally sweet, and additionally quite clever. A coworker and I dived into how it figures out what method to stub today and that alone was enjoyable.

Mockito will definitely be a valuable tool to have in the testing toolbox.