Leveraging Eclipse for TDD

I have found that quite a few programmers struggle to work in a completely test driven fashion. I myself whilst writing tests for many years, took a long time to move over to writing the test first. I think one of my problems was that I always wanted to do my thinking in the implementation class. Recently I have found a great way to leverage the Eclipse IDE’s code complete functions so that its more natural to work from the test class.

The idea is to save effort and time by getting Eclipse to create the implementation side. I have long been used to changing the code, and then using code complete to refactor. For instance you can change a class name or package name, and use CTRL-1 to get a list of options on the code that will not compile. Then use an option to move or rename the class performing the re-factor.

This turns out to be a very powerful technique for driving development from the test.

Try out this simple example I think it makes it more natural to TDD, but I would be interested in your comments.
Continue reading

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Eclipse, Static imports quickly and GitHub gist.

Every one has a collection of favorite Eclipse templates.  I find the simple ones are often the most useful.  The examples below create you a static import and finish the method your typing.  They even put the cursor in the right place if you need arguments in the method.  I am going to collect more of them using the incredibly handy GitHub gist: My Static Import Templates For Eclipse.  GitHub gists are great for these kinds of programmer reminders.  In addition edits get version control.

Typical Eclipse template for Google Collections

${:importStatic(com.google.common.collect.Lists.newArrayList)}newArrayList();
${cursor}
${:importStatic(com.google.common.collect.Sets.newHashSet)}newHashSet();
${cursor}

To use them, just open Eclipse Preferences: Java Editor: Templates.  Add new templates, and give them a name similar to the method.  I.e newArrayList.  Then your code completion hot key will run the template completing the text your typing in.  i.e you type newArrayList [code complete key] and it adds the static, and the rest of the method, placing your cursor at the end of the line.  Neat!

Note: See the comment from Yuri below, the above templates are no longer required for static imports. Its possible to configure the Content Assist to bring in a whole type, or member using Prefs:Java:Editor:Content Assist:Favorites. This is better as it scans all possible available methods in the type.

The code you end up with is tidy too:

List myList = newArrayList();

There is another thing I can never remember the syntax for! :-)   The markup to add the syntax highlight for this blog. Available as a gist: http://gist.github.com/234709

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Racing with Roo

In my last post I said that I would have a deeper look at Spring Roo. Well I still have not quite done that. But I did have a race to see how long it would take me to get my first website up and running with STS and Roo shell. The previous night I downloaded STS, and today I installed it on my Linux server, all very smooth no issues. Next I found a roo shell tutorial to follow: Roo Shell Tutorial Part 2 from the SpringSource blog by Ben Alex.  This uses roo from the prompt, I am going to use the shell in STS.  The challenge is to follow the tutorial and take timings to get some understanding of how difficult it is to get going with Roo.

  1. 21:45 Open Eclipse.
  2. 21:49 Updates downloaded and maven re-indexed.
  3. 21:53 Start tutorial, lots of downloads from maven after project creation.
  4. 21:55 Restart eclipse to enable the runtime weaving, STS does not return…restarted it from the prompt, deleted the project and started again as it looked incomplete.
  5. 22:00 Bumbling through the tutorial.  This is very easy, love the CTRL^space completion.  I have done quite a bit of Linux work, and this shell is very easy to use.
  6. 22:14 Running the tests using roo> perform test. This runs maven, which fails because it cant find the integration test class, RsvpIntegrationTest.  Investigation from the bash prompt reveals that all tests pass under maven, so its not an issue with the project roo has created.  More download and fiddling about.  The test runs from eclipse too, so I move on.
  7. 22:38 Website up! Selenium tests all pass.  Investigation of the functionality shows that its working!  Done in 53 mins not bad I think!
Roo Up and Running!

Roo Up and Running!

Conclusion

Yea easy, a quick look over the project shows its very neat and tidy. Most of the time was spent in download and the false start. The configuration easy to follow and the generated code would be easy to use. So yes, might have a proper look at Roo at some point! ;-)

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Quick look at the latest SpringSource STS and Roo

Christian Dupuis from SpringSource shows some of the new features on the SpringIde Blog

I used Spring STS for a few months before starting at Lab49, and found it to be a good distribution over the standard Eclipse build. It has lots of extra productivity features for Spring based development some of which are not available by downloading Spring plugins and adding them to a normal distribution.
The things I like best are:

  • The edit, navigation and search systems now support the spring annotations. So now you can navigate and search for beans declared via annotations.
  • Ability to include new XML domains in the spring configuration from a popup list.
  • The enhanced XML editing support now has inline error checking.
  • This XML editor also supports completion and checking of class and bean names.
  • Roo shell looks interesting too.

Roo and Roo Shell
The Roo system looks great. Its a system to generate and support a JEE system. The roo shell can be used to configure JEE components. You can have a basic website up in seconds. Like Groovy and Grails you get spring standards built in, and your not dependent on the Roo system once your finished.

I am going to take a proper look at it at some point.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)