Jun 23 2009

Doing more with jUnit: faster, cleaner unit testing

Category: Java,TestingPhil @ 9:20 pm

These are not really new features, but I bet most developers (like myself) have not given them the attention they deserve! Earlier this month, I read an interesting article on the Atlassian Developer Blog which peaked my jUnit interest. I remember reading about these features when jUnit 4.4 was released a couple of years ago (release notes), but I never took the time to try them out. JUnit included new abilities and concepts, such as Assumptions and Theories. To be real honest, the Assumptions and Theories sound really good in theory, but I’m not sure how practical they are in the real world! How can you argue with definition of a Theory… More flexible and expressive assertions, combined with the ability to state assumptions clearly, lead to a new kind of statement of intent.

First, I’m not sure how well Spring and Theories actually play together. They both need to have their own @RunWith annotation. Second, it is hard enough to get some developers to create a simple unit test! I will have to do some more pondering on Theories. Also, don’t get too carried away with the assumptions without doing some more reading; they have some rather unexpected behavior. Assumptions cause future assertions to pass, irregardless of the asserted value! Interesting?

The real power is in the “Matcher” functionality provided by Hamcrest, creating new capabilities (without writing additional code), a cleaner assertion syntax, creating more readable unit test code. Check out the multitude of convenince Matchers that are provided from Hamcrest. I focused on the power of the assertThat() method. The following code snippet demonstrates a couple of the matchers that I could have used a dozen times in the past and probably implemented my own nasty, non-reusable solution!

	@Test
	public void assertions() {

		final String colors = "color me crazy";
		final Collection<String> colorList = new ArrayList<String>();
		colorList.add("color");

		assertThat(colors, either(containsString("color")).or(containsString("colour")));

		assertThat(colorList, either(contains("color")).or(contains("colour")));

		assertThat("custom error message", colorList, //
				not(either(contains("red")).or(contains("green"))));

		assumeThat(colorList, contains("red"));
		fail("jUnit Still successful!! Does not fail!");
	}

Random Thoughts…

  • jUnit 4.6 was recently released (release notes). I did not see anything exciting in new new release, other that some new integration with JUnit Max.
  • As cool as JUnit Max sounds, it is now dead to me! The subscription fee has jumped to $10 per month… That is more than my XM Radio subscription!!! If continuous testing is really that cool, hopefully, other smart people are working on even better, open-source alternatives!
  • The Spring 2.x framework integration was broken with jUnit 4.5 and required version 4.4. The new 3.x version of Spring, still in beta, works with both 4.5 and 4.6. It actually no longer works with 4.4!
https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


Jun 15 2009

Galileo Eclipse Update

Category: EclipsePhil @ 6:27 pm

I might be in the minority, but I’m just not that excited by this release of Eclipse. I started using the RC3 version for real last week, and have had no issues at all; it seems very solid.  I attempted to use with the first couple release candidates, but they did not seem to play well with the Subversion plug-ins. I’m sure it was user error; it could not have been that messed up! For whatever reason, Eclipse completely toasted my work area (multiple attempts) after every commit. Needless to say, I did not even bother using them.  I have Eclipse integrated with the Spring IDE, Checkstyle, PMD, and Ivy plug-ins. I heavily use the Web Tools Platform for deploying web applications to Tomcat.  At least for what I have been doing lately, there is nothing to get me really excited. I think the best part is, that everything still just works! I notice a new little feature every so often, but nothing that says that’s a keeper! I have been using the Implementors plug-in for many years and was glad to see they finally implemented this feature within Eclipse. It works pretty well,  but they only implemented half of the functionality! With the Implementors plug-in, you can click on the interface method and ask to see all of the concrete implementations.  You can, sort of, get the same functionality through the type hierarchy view, but not as nicely. After seeing the Open Implementation feature, I thought this was a new feature too; I did not know that you could just click on a URL and have it open up in the browser, kind of handy!

One other thing that seems new, is the ability to search using partial camel-case entries. If you are really lazy or can not spell worth a crap, then you will probably use this feature a lot. Simple type in mixed case letters in the entry field, and Eclipse will automatically match to those classes. I thought the bold-ing of the matched letters was a nice touch.

There are two features that need some work, especially when you are moving between (upgrading) Eclipse versions.

  1. I thought the Clean Up and Save Actions functionality were excellent additions to the Ganymede release. I still can not figure out why I have to enter my configurations on both option panels. You can import/export the configuration on the Clean Up panel, but not on the Save Actions panel; you have to re-enter everything. I understand that some people might want different behaviors, but you should at least be able to import/export your settings on the Save Actions panel too; allowing us to reuse the other panel’s settings. I thought for sure this would have been fixed, small  bummer.
  2. The Content Assist Favorites drives me crazy, especially because I’m a big jUnit believer/implementer. Because I only use jUnit 4.x annotations and static import assertions in my unit tests, Eclipse is not smart enough to add the imports when I hit <CTRL><SHIFT>o or ask for the content assist. Maybe I learned something new tonight, from this blog.  I typically enter all of the jUnit assertion signatures (method names only) that I typically use. It looks like their might be an easier way, just by specifying the Type, I will have to try this tomorrow! Personally, I think jUnit assertions should be added by default, but that is just me!

If I’m missing out on a new killer Eclipse feature that was added to Galileo, please let me know! I don’t want to take away any of the great work that was done on this release, unfortunately, I don’t use any of those new additions! But I don’t think you can go wrong with this upgrade.

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


Jun 14 2009

New Trees… Like we don't have enough!

Category: MiscPhil @ 6:40 pm

Fortunately, we only lost a couple of trees last summer due to the drought.  Unfortunately, there were both relatively close to the house, so they really needed to be replaced. Amazingly, there were only two trees on our lot when we purchased it, now there are over two hundred! Call me crazy, I push mow around all of them before mowing with the big mower! I can’t believe how these trees have grown; we purchased about 150 Evergreens that were only 18 inches tall; many of them are over 10 fee tall now. Pretty cool!

We found a nice little nursery up in Frederick MD this weekend,  The Dutch Plant Farm. We live far enough to the west, that we can actually go up to Frederick, out to Winchester, or over to West Virginia; the distance is about the same any direction we go! The staff was very helpful and the prices were more reasonable than some of the big Northern Virginia nurseries.

One of the trees we lost was a six year old Japanese Maple. We wanted to replace it with another one, but were a little worried about their hardiness and cost. Between the hot, humid summers, too much rain, not enough rain, and the crazy amount of wind we get in the winter, we have some pretty tough tree growing conditions!  We ended up purchasing a different variety of Japanese Maple, one that was a little more tolerant of direct sunlight, a Red Dragon.  I obviously need to do some mulching, but it is a really pretty tree. The other tree we lost was a Harry Lauder Walking Stick; it was several years old too, but never really did that well.  We decided to replace it with a Raspberry Sundae Crapemyrtle. Living in the south, you see so many Crapemrytles, I think they are one of my favorites; especially when they start blooming. Hopefully, they will both survive the summer heat; I guess I will just have to keep up with my watering!

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


Jun 10 2009

Hudson Continuous Integration and Eclipse Update Sites

I was looking for a development build of the IvyDE plug-in for Eclipse tonight and I stumbled across the Apache Hudson server. You have to check this out. Pretty cool, Hudson running over 150 jobs!  Their build farm consist of both Solaris and Ubuntu servers. What I found most interesting was how they used Hudson for creating an Eclipse update site. I subscribe to the Hudson mailing list, summarized here, to follow what is going on with the project. People seem to use Hudson for a variety of different purposes, such as a cross platform testing tool and even as a deployment tool. I have only been able to get people interested in Hudson as a “Cruise Control” replacement…. but at least it is a good start!

This site also demonstrates how multiple projects can be linked together, triggering builds of dependent downstream projects.  I’m not exactly sure how these jobs were assembled, but at a high-level, Ivy and IvyDE each have its own build loop (job). Each job is responsible for creating build artifacts. After a successful build of either job, a third job is triggered which creates/updates and Eclipse update site.  Pretty slick. (As any FYI, the dev plug-in looks better, new presentation and several new new options)

Another small plug for Continuous Integration. We recently set up something kind of cool (trivial, but cool)! As we continue trying to convince the powers that be, to move away from Weblogic towards Tomcat (or even JBoss), we found a really nice little feature. Since Tomcat and JBoss can hot deploy a new version of the WAR file, just by noticing a difference on the file system, combined with the fact that we can spin up a Tomcat instance in about 2 minutes, we actually created an auto deployment mechanism.  Our Weblogic environment seems so cumbersome in comparison…. We could have built the WAR and deployed in in our build loop, but that would have minimally added another 25 minutes to the loop (let’s just say we have an interesting deployment process). With Tomcat, we did a one time deployment to the location of the WAR file inside the Hudson workspace. Now, with each series of check-ins, we build the WAR as normal and Tomcat instantly deploys it, in seconds! If we were a little more sophisticated, we would write some jUnits to bang against it, making sure we did not break anything or create any new dependencies.  Maybe I will throw that in during my next project!!! I know this integration was possible before (with Weblogic), but no way as simple!  Even better Continuous Integration… on my last project I had Ant spin up an embedded Jetty web server, ran my jUnits against the Clover instrumented code, and finally had Ant shut down Jetty…. Pretty slick, from a code coverage collection perspective…

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


Jun 07 2009

Spring Framework XML Schema Extensions…

Category: JavaPhil @ 8:20 pm

Seems like every time I dig into Spring, I learn something new. This week, it was the Spring Util schema. Like most developers, I never take the time to read the manual and usually only have enough time to get the job done. Unfortunately, the rush to get done typically highlights some features that I really did not understand or used improperly. I seem to get a lot more out of reading the documentation after seeing how all of the pieces go together. Fortunately, I’m usually not satisfied with this level of mis-understanding, so you are forced to read about how I fixed my mistakes!
Generally, if you are only using the IoC container feature of Spring (dependency injection), you can usually get by using the simple bean schema. I have messed around with Aspect Oriented Programming (AOP) integration using the AOP schema, but never used it in a real project and I always use the Transaction annotations, so I never bother with the Transaction schema either! When I started integrating the Spring Security framework into my last project, my Spring XML files started looking a little different, I started qualifying all of my bean tags.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
                         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
                         http://www.springframework.org/schema/security
                         http://www.springframework.org/schema/security/spring-security-2.0.1.xsd">
<security:global-method-security
secured-annotations="enabled" jsr250-annotations="enabled">
</security:global-method-security>
<beans:beans id="dateTimeBean" class="org.beilers.DateTimeBean">
</beans:beans>
<beans:beans id="timeDependentBean" class="org.beilers.TimeDependentBean">
<beans:property name="currenttime">
<util:property-path id="name" path="dateTimeBean.currentTime" />
</beans:property>
</beans:beans>
</beans>

I will write about the Spring Security framework in future post, but I wanted to highlight the Spring Util schema. I ran into a scenario last week where I wanted to use a property in an existing bean, to set a value in another bean; I could not pass in the bean, only the property. With the standard bean tags, there is no way to navigate a bean property path, such as bean.bean2.property. I knew there had to be solution to this problem, it seemed too common. With a little Google-ing help from a friend, we ran across the Util schema. There are some really convenient tags to help you manage your Spring configuration files. In the above example, I demonstrated the property-path tag to demonstrate path navigation. There as also other tags for accessing constants and fields, creating reusable lists and maps. Make sure you give this document a read, it can save you time and make your code cleaner and even add some type-safety to your XML.

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png


Jun 02 2009

The Best Eclipse Plug-ins

Category: EclipsePhil @ 8:50 pm

I’ve ran across several blogs that listed their favorite Eclipse plug-ins.  Since I am such a huge Eclipse fan and am always preaching about the power and benefits, it seemed like a good idea for me to document my preferences and experiences. First, you need to start with the Eclipse Java EE version, probably the Ganymede version (3.4), but Galileo (3.5) will be released next week. This Eclipse bundle will give you more than you need, but is the best starting point. Out of the box, Eclipse has many useful features:

  • Mylyn – Task focused development support; here is some background information.
  • Web Standard Tools – Gives you all of the nice editors for XML, HTML, JSP, etc.
  • J2EE Standard Tools – Provides support for J2EE projects, such was the Servlet and EJB.
  • Remote System Explorer – Excellent plug-in for accessing remote systems. It enables you to remotely edit files and provides shell access, including SSH.

Here is my personal Top 10+ list of Eclipse Plug-ins:

Category Plug-in Overview
Code Quality Checkstyle Simple to use. Great for keeping the code consistent and helps enforce many good coding standards. My only dislike of this tool is the suppression implementation. Hopefully they will move to the PMD annotation style. A major new version (5.0) was just released, I have not tested it yet.
Code Quality PMD Little more complex to setup than Checkstyle, but is probably my favorite plug-in. It looks at the structure of your code, evaluating cyclomatic complexity, jUnit usage, and attribute scoping. It has some overlap with Checkstyle, but both tools together give you a complete solution.
Build Support Ivy I have blogged about Ivy in the past. Not my favorite plug-in, but required when using Ivy within Eclipse. If you work on multiple projects or do a lot of prototyping, Ivy is an awesome time saver.
Construction Spring IDE If you develop Spring-based applications, you will want to install this plug-in; it is a must have! The plug-in has numerous helpful views; and makes creating and managing your context files much simpler.
Construction Log4E Log4E make Java logging significantly easier, no more cutting and pasting from other classes. The free version supports the common logging frameworks, but unfortunately not the current open-source community favorite, SLF4J.
Construction Subversive This plug-in is used to integrate Subversion into the Team Perspective/View. It also appears to no longer be required with Eclipse 3.5.
Construction Subversive Team Provider There are two options for integrating Subversion into Eclipse, you can choose either the Tigris or Polarion implementation. The Tigris plug-in seemed easier to get working, but has less features than the Polarion implementation. I started with Tigris, but have settled on the Polarion version about a year ago.
Construction Implementors This plug-in allows you to navigate from any interface to an implementation of that interface. Especially helpful when you are programming with the Spring Framework. This feature is finally part of Eclipse 3.5, so you might not needs this one any more.
Testing Clover Clover is my only commercial plug-in; Clover is used to collect code coverage metrics. You have to be a little careful when using this plug-in. Never let Clover instrument the entire project, Eclipse will most likely become completely unresponsive and unusable. If you have a large project, I highly recommend using Eclipse Working Sets to selectively control which files you collect coverage data on.
Testing Findbugs This is actually on my to do; I have been very happy using Findbugs thru Ant, but have not had a chance to try out the plug-in.
Database SQL Explorer A database explorer tool is included with the Java EE Eclipse bundle, but it seems to have some usability issues. Most developers seem to be very dissatisfied with the included version and prefer the SQL Explorer plug-in. Probably not perfect, but it works good enough for us Java guys.

Just a random link of several more plug-ins, http://www.plentyofcode.com/2007/07/most-useful-top-50-eclipse-plug-ins.h6tml There were a few plug-ins on the list that looked interesting, maybe you will think so too. Make sure you read the comments!

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png