junit

How to use JUnit with Scala

Problem: You want to test your Scala code using JUnit.

Solution

Include the JUnit library in your project, and use it in the same way you’ve used it in Java projects, with a few minor changes.

Assuming you’re using SBT on your project, include JUnit into the project by adding this dependency line to your build.sbt file:

Spring Dao/JDBC tip - a great way to test your Spring DAO code

The Spring Framework gives you a great way to test your Spring JDBC (Spring DAO) code. Just use a special Spring JDBC class with a very long name, and you can test your Spring JDBC code against a real database.

Some people don't like this approach, but I think it's invaluable for (a) testing your SQL syntax when you first create it, and (b) making sure your SQL syntax is still valid after database changes occur.

An Ant 'exclude classes' example

Problem: You want to build your Java project using Ant but you need to be able to skip certain files -- typically unit test files -- during the compilation or deployment processes.

Solution: You can skip files during the Ant compilation process by using the Ant exclude pattern. Here's an example that shows several exclude patterns in some XML code taken directly from an Ant build script:

How to compile a Java program with Ant

While I'm digging around through Ant build scripts today, here's a sample Ant target I created that demonstrates how to compile a Java program, while also showing a few other things, including how to exclude your JUnit tests during the compile process.

Unit tests - documentation you can compile

In the category of best practices I have to include my thoughts today on unit tests as a form of "comments/documentation you can compile". Let me explain:

I recently had the experience of (a) working on a small but complicated software development project, (b) leaving that project for six months, and then (c) being asked to work on it again. All I can say it wow -- what a great experience it was to come back to a project that was loaded with unit and code coverage tests.

A Java email address validation class

I thought I'd share the source code for my Java email address validator class. I'm not sure if there's a big need for it ... I wrote it a long time ago, and I think I created it because Java's javax.mail.internet.InternetAddress class wasn't validating email addresses as deeply as I wanted it to. For instance, I think it would allow the string "fred" to be a valid email address, but on the internet you really want to see something like "fred@foo.bar". So I think that's where this class comes from.

Sat, Feb 8, 2003

While reading a book on TDD (Test Driven Development) from Kent Beck, I ran across a reference to Jester, which is apparently a JUnit test tester. Like many things lately, I haven't tested it yet myself, but it claims to "find code that is not covered by tests". If it works, that would be pretty cool.