6

I'm having a hard time making the connection between testing and code. I could ask numerous questions here about things like directory structure and naming of test classes and JUnit 3 vs 4 and so on, but I'd rather find a sample project that does it right and learn by reading it.

I'd like something not too complex so that I can understand it easily, and JUnit 4 would be best (no reason to stick with 3 since I'm starting fresh, right?). I'm on Windows 7, I use Eclipse and I'm planning/hoping to learn and use Hudson. I like Ant, haven't had a good experience with Maven but that's cool too.

Is there a sample project out there that fits this criteria?

edit: Neither of these answers mentioned Hudson; I really like the Craftsman articles (and maybe it goes into continuous integration) but does anyone else have any other suggestions?

Ricket
  • 33,368
  • 30
  • 112
  • 143
  • For reference, we use Hudson for CI and Maven for build. Another project that you may be interested in is Sonar - which runs code analysis metrics on your code (http://sonar.codehaus.org/). – Martin Mar 05 '10 at 21:29
  • Sonar looks neat. I just installed the plugin to Hudson, so whenever I start actually practicing these concepts, it will be there to help me analyze my code. (I've had Hudson installed for a while but it currently has no projects yet) – Ricket Mar 08 '10 at 01:55

2 Answers2

6

I found the Craftsman articles by Robert Martin (Uncle Bob) an excellent resource for learning effective unit testing. It focuses on Test Driven Development and walks you through the experience of a new coder learning how to test code. The first article can be found here and is called The Craftsman #1: Opening Disaster.

Martin
  • 7,089
  • 3
  • 28
  • 43
3

If you're looking for an easy example of project structure and convention, I would recommend giving Maven another go. To use it with Eclipse, install the M2Eclipse plugin, and create a Maven project using one of the Maven archetypes. The archetypes build simple template projects, including source and test structure, and will run with Maven and Eclipse right away.

Daniel
  • 10,115
  • 3
  • 44
  • 62
  • Thanks, I might reconsider it. I've heard that Maven is extremely popular, so there must be something there... – Ricket Mar 04 '10 at 07:47
  • 1
    I wish I could accept both answers. Over the past few days I set up Maven and the M2Eclipse plugin, and got it all hooked into my server running Hudson and Sonar and SVN, and it's really quite an amazing setup. But the Craftsman articles from the other answer got me in the right mindset. – Ricket Mar 09 '10 at 07:37
  • Hehe, no hard feelings. Glad it helped! Maven/Sonar/Hudson is definitely a good combination. – Daniel Mar 10 '10 at 00:44