An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Eclipse and jUnit

April 18, 2007 · 16 Comments

I'm doing some consulting right now that has me writing Java code. The more Java I write, the more I'm reminded of why I like ColdFusion so much but that's another story. The company I'm consulting for likes unit testing, which makes me very happy. They actually require that a unit test exists for every method in every class (and in every CFC - yes, they build stuff with ColdFusion as well). Surprisingly, this is my first exposure to jUnit. Yeah, I know, I'm such a big fan of cfcUnit, how can I never have used jUnit? Anyway, I write my TestFoo.java class with its setUp() and tearDown() methods and start writing testMyMethod() methods. Then it occurs to me: how do I run this? I'm so used to the browser-based runner for cfcUnit that I'd never thought about the Java equivalent. Out of curiosity, I right-clicked in the editor panel displaying the test case and there, in the Run As... submenu: JUnit Test. Wow! Really? Could it be that simple? Yup! Up pops a JUnit view in the bottom panel running my tests and showing a red failure bar and list of failed tests. Perfect! Well, of course my tests failed - I just wrote the tests. Next I'll write the code. As is so often the case, Eclipse continues to surprise me in pleasant ways! Now, where's the cfcUnit plugin?

Tags: cfeclipse · programming

16 responses so far ↓

  • 1 Maxim Porges // Apr 18, 2007 at 8:22 PM

    This is the kind of stuff that makes Eclipse so kick-ass for Java. I don't think I'd love Java development anywhere near as much as I do without Eclipse 3.2.

    Not sure how new you are to Eclipse with Java, but please tell me you've played with the refactoring and code-gen features already?

    Of course, I'll be boring you to death with all this in my talk at cf.objective()... :)

    - max
  • 2 Sean Corfield // Apr 18, 2007 at 11:18 PM

    @Maxim, I haven't done much with Eclipse's refactoring but I've been a long-time fan of Together (Borland's product now) which has supported a slew of refactorings for many years.

    I started using Together back in '97 I think and introduced it to Macromedia in '99 or '00. It's always had a variety of great refactorings as well as software metrics and coding standards compliance checks.

    I'm looking forward to your talk at cf.Objective()!
  • 3 Brandon Harper // Apr 19, 2007 at 12:54 AM

    The two biggest features in Eclipse (for Java) that I like are it's refactoring capabilities, and it's tight integration with JUnit. It's really kind of amazing to me how many people use Eclipse now.

    I would think about giving NetBeans a try if I wasn't already soured by all of the Sun employee blogs chest-thumping about how cool it was about 50 times per day. Come to think of it, I guess that's largely a similar reason BlueDragon isn't on my radar either.
  • 4 Mark Drew // Apr 19, 2007 at 1:22 AM

    Sean, have you checked the CFEclipse update site in the last couple of days? notice the extras ? ;)

    I shall post more on this when I get my head round cfcUnit...
  • 5 Jim Priest // Apr 19, 2007 at 6:09 AM

    I thought Mark was working on cfcUnit integration - I think it was in the last beta but he stripped it out of the final release... Maybe he'll announce something at one of the upcoming conferences.
  • 6 Qasim Rasheed // Apr 19, 2007 at 8:04 AM

    In addition to refactoring support in Eclipse, which is amazing, I have found the shortcut CTRL+1 to be of a terrific help.
  • 7 Sean Corfield // Apr 19, 2007 at 9:26 AM

    @Mark, I just installed that extra - once it works with cfcUnit, I'll be a happy camper (cfcUnit is far superior to CFUnit in my opinion).

    @Qasim, it's Command+1 on a Mac (and for folks who didn't know, it's a local rename - that updates all references to renamed item).
  • 8 Qasim Rasheed // Apr 19, 2007 at 2:34 PM

    Sean,

    Whenever I have used Ctrl+1, its been more than just local rename. Let's suppose we have a class name Person with no argument constructor. Now in the calling code, if we try to create an instance by using Person p = new Person('CFDeveloper'), the built in complier will complain and Eclipse will place a red mark. Now if you click Ctrl+1 on the error area, Eclipse will present you with an option to create a constructor in your Person class with a string argument.

    Is that what you mean when you said local rename?

    Thanks for the tip though.
  • 9 Sean Corfield // Apr 19, 2007 at 2:43 PM

    @Qasim, ah, that's interesting... when I tried it on some code it just offered me the option of renaming the variable or method under the cursor. I'll try it on some more code... sounds like it'll save me some time.
  • 10 Chris Scott // Apr 19, 2007 at 5:34 PM

    I have dreamed many times of the day when running cfcUnit tests was so easy! The project I am working on now has a heavy set of unit tests in a test suite that is part of the build, so it kind of mandatory. @Maxim, believe me, if you worked with intellij IDEA for a while, you would live without eclipse in a heart beat. Now that is coding bliss!
  • 11 Maxim Porges // Apr 19, 2007 at 5:55 PM

    @Sean,
    Looking forward to seeing you there next month! I've never used Together, but I'm sure the refactoring support is just as good as that in Eclipse. I got exposed to this sort of refactoring tooling in Eclipse first, so it's my first love. Of course, since Eclipse also rules the world of non-.NET IDEs and plug-ins, I love having all my tools in one box: Flex Builder 2, Rational Software Modeler, Subclipse, the Spring IDE, a Tomcat runner/debugger for round-trip debugging Flex and JSP apps, and (of course) CFEclipse.

    Since we're having a free-for-all on Eclipse features, I'll give a shout-out to some of my favorites.

    Command-Option-Z ("Surround With...") is a biggee; lots of options including try-catch, for/do/if/while, synchronized, and runnable). Quick Fix (Command-1) is great for a lot of different things depending on the context of the red line your cursor is in when it's invoked.

    As for code generation, I love Command-Option-S, which does a ton of stuff - everything from various comment blocking, to my favorites: Override/Implement Methods, Generate Getters and Setters (must define private class-level variables first), and hashcode()/equals() generators.

    While all the refactoring is awesome, my favorites/commonly used ones are the moves, extractions, and pull up/push downs. I usually like to design stuff before I get coding, but when I want to knock together a quick POC or get an idea out of my head, it can get messy. These refactorings make it so easy to clean things up in a matter of minutes once the solution is complete.

    Finally, since I'm a keyboard Nazi, I have a few time savers for running methods and test cases: Command-Option-W pulls up the "Show In..." dialog, and then you can arrow to "Package Explorer" and hit return. If you do this in a method, it will actually select the method in "Package Explorer" for you. Then, if you invoke Option-Shift-X (and wait...) you get a little pop-up menu in the bottom right for what you want to run. Simply hit "T" to run your Test Case, or "J" to run a Java app. I love it.

    - max
  • 12 kola // Apr 23, 2007 at 8:51 AM

    I began to post this as a comment and expanded on it on my blog but I think it's relevant in this discussion too. In a conversation with a friend recently who has worked in anger with both ColdFusion and Java - he made the comment that he felt that working in Java is actually *more* productive than working in ColdFusion due to its great tools support. I'm not convinced. But then again every time I pick up Eclipse and start using the refactoring support and everything else it does make me think. I *feel* more productive in ColdFusion and there seems to be an assumption that you can be I wondered what everyone else's thoughts are on this.

  • 13 Sean Corfield // Apr 23, 2007 at 11:24 AM

    @Kola, short link to your blog for my readers who don't know?
  • 14 Sean Corfield // Apr 23, 2007 at 11:25 AM

    Never mind, I found it:

    http://coolskool.blog-city.com/
  • 15 Andrew Scott // Apr 24, 2007 at 5:07 AM

    @kola, I have to agree with the tools that java has at its disposal. I mean with so many unit tests and build tests etc its a shame we haven't go some of this yet.

    CFCUnit & CFunit are great examples of getting there, but when you look at tools like maven and a few others it makes builds and Life Cycles great for management.

    I would really love to see junit clone for CF, in that I can view the fail/sucess in the same manner as junit.

    And refactoring, what another story that is in the java world that would be great for us.
  • 16 Sean Corfield // Apr 24, 2007 at 8:13 AM

    @Andrew, you say "I would really love to see junit clone for CF" but that's exactly what cfcUnit and CFUnit are. cfcUnit shows you fail/success information and the CFUnit plugin for CFEclipse - which works with both cfcUnit and CFUnit - shows you almost identical information to the jUnit plugin.

    Furthermore, cfcUnit (and CFUnit) can be run from ant, again showing fail/success information, as well as from a browser. cfcUnit also has a great Flex front end, courtesy of those folks at asfusion.com.

    My previous team used cfcUnit and the ant integration in Eclipse to automatically run unit tests whenever you changed a file. We also used CruiseControl to automatically create and deploy builds.

    There are plenty of tools for automating test / build lifecycles with ColdFusion.

Leave a Comment

Leave this field empty: