Mutant World

Wednesday, May 31, 2006

TestNG and Maven

I've been working with JDK 5, and some time ago I decided to try TestNG as test framework, leaving back JUnit.

Since then, I got addicted to TestNG, and if possible, will never go back to JUnit, as really TestNG is leaps beyond JUnit.

Now I am working also on a JDK 1.4 application that I build using Maven.
I've been really impressed by the fact that Maven supports TestNG out of the box, even in JDK 1.4 (using Javadoc annotations). Well, time to convert all tests from JUnit to TestNG, and it's very easy:

Before:

public class MyTest extends junit.framework.TestCase
{
public void testSomething() throws Exception
{
assertTrue(true);
}
}


After:

public class MyTest
{
/**
* @testng.test
*/
public void testSomething() throws Exception
{
assert true;
}
}


Plus, you get all cool TestNG features:

  • configurable advice methods (that run before/after the suite, the groups, the class, the test)

  • configurable dependencies among tests

  • configurable number of runs

  • configurable parameters to pass to the test

  • ...and much more

Friday, May 26, 2006

Big Changes and 2 Linux hacks

Long time, no blog entries.
I have to say that my life changed quite a bit: a newborn baby to take care of (Riccardo), a new job and soon a new house.

Another thing that I changed (less important than the above, but daily used) is the operative system: I've switched from Microsoft Windows to Kubuntu Linux.
The move was painful, especially at the beginning, and IMHO still not possible for an average user. For my mother it would have been impossible to figure out how to make wifi and video card working, let alone the modem, on my Lenovo T43p.

However, I recently found 2 useful Linux hacks.

First Hack: How to avoid duplicate commands in the bash history (when you hit arrow up in a shell).
Open ~/.bashrc; at the beginning of the file there is an entry such as:

export HISTCONTROL=erasedups

It's probably remarked, or has another value. Setting it to 'erasedups' made the hack.

Second Hack: How to correctly configure /etc/hosts when using DHCP.
It turns out that the dhcp client may run scripts when it binds (and when it releases).
The scripts for binding are /etc/dhcp3/dhclient-enter-hooks, and all the scripts inside directory /etc/dhcp3/dhclient-enter-hooks.d/.
Correspondent scripts for releasing are /etc/dhcp3/dhclient-exit-hooks and those inside directory /etc/dhcp3/dhclient-exit-hooks.d/.

The script dhclient-enter-hooks was missing in my configuration. I created it and put this inside:

#!/bin/bash
#
# This script updates /etc/hosts with the address received by the DHCP server
#
HOSTS=/etc/hosts
BACKUP=${HOSTS}.original
LOCAL=${HOSTS}.local

make_etc_hosts ()
{
cp -a $HOSTS $BACKUP
cat <<EOF > $HOSTS
# This file is generated by a script: do no edit; edit instead $LOCAL
# Created by $0 on `date`
127.0.0.1 localhost localhost.localdomain
$new_ip_address `hostname`

# The following lines are desirable for IPv6 capable hosts
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

# Entries from file $LOCAL, if any
EOF

test -f $LOCAL && cat $LOCAL >> $HOSTS
}

if [ "$new_ip_address" ]; then
make_etc_hosts
fi


With this script, /etc/hosts gets regenerated every time the dhcp client runs, and assigns the IP address received via DHCP to the hostname of the computer.
Still not perfect (if you have multiple network interfaces), but it's possible to improve it.
For me, for now, does the job :)