TestNG, test groups, IDEA, and @BeforeMethod

Say you have

public class SomeTestNG {
@BeforeClass
public void setup() {}
@Test
public void test1() {}
@Test
public void test2() {}
}

You’ll get the following methods invoked:

  • setup()
  • test1()
  • test2()

Not surprising.

What happens, though, with this?

public class SomeTestNG {
@BeforeClass
public void setup() {}
@Test(groups = {"database"})
public void test1() {}
@Test
public void test2() {}
}

And you run the “database” group?

Does setup() get called?

It’d have to, right?

Well…

Not so much.

Not so much.

@BeforeClass has a groups() attribute as well, and it’s respected when you run group test suites. If you want it to run before all methods, you need to use the alwaysRun = true:

public class SomeTestNG {
@BeforeClass(alwaysRun = true)
public void setup() {}
@Test(groups = {"database"})
public void test1() {}
@Test
public void test2() {}
}

What’s a serious humdinger–when you run the test manually in IDEA, you’re running the test outside the scope of it’s group test suite, so the @BeforeClass runs as expected. Only in ant will the @Before… fail to get called.

Preventing an external hard drive from idling on ubuntu

I got a Seagate FreeAgent Pro external hard drive for backups (JWZ has a very straightforward article about this). It happily reformatted to ext3, and I kicked off an rsync of /home.

Because rsync figures out what files need copying before it copies them, and there are hundreds of thousands of files in my /home, there was more than a couple minutes of grinding on the local hard drive building a list of files to copy over. While this happened, the external drive idled into a “sleep” mode that ubuntu can’t seem to awaken it from.

This was slashdotted with an sdparm hack, but I believe this solution is better. Copy this new udev rule into /etc/udev/rules.d/50-local.rules (this is a new file that you will be creating):

# Seagate FreeAgent allow_restart fix (i/o errors)
SUBSYSTEMS=="scsi",DRIVERS=="sd",ATTRS{vendor}=="Seagate*",ATTRS{model}=="FreeAgent*",RUN+="/bin/sh -c 'echo 1 > /sys/class/scsi_disk/%k/allow_restart'"