Just for something to do, I'm learning? Scala. Having deep confusion making JUnit suites run. Advise me in comments if you're up for it?

Reading Venkat’s book, and Dean Wampler’s book, I decided that rather than run things at the command prompt … how very last century, I’d write a bunch of JUnit tests to test and document the things I was trying. It seems to me to be a much better way to do things.

(Why am I not using ScalaTest or another such system? Largely because I know JUnit and felt no desire to try to learn two things at once. And yes, I know I should get a Mac.)

It’s going pretty well so far, or was until I tried to set up a suite of tests. I’ve got a big JUnit test file, and it was just getting irritating to add another test to it, so I started another one, thinking maybe someday they’d even get organized. But of course I’d like to run all the tests frequently just because I like the jolt of the green bar.

So I looked up how to do a Suite. There’s nothing really solid on the Web but I found a couple of consistent items. They are almost working but some of it has me confused. I’ll note down here what I’ve got and maybe if you grok Scala you can advise me in the comments.

I have my main test file. It looks like this:


import org.junit._
import org.junit.runner._
import org.junit.runners._
import Assert._
import StringUtil._

class TestSomething { 

	@Test def hookup() {
		assertEquals(2,2)
	}

	@Test def someArrayStuff {
		val array: Array[String] = new Array(5)
		array(0) = "abc"
		assertEquals("abc", array(0))
		assertEquals(null, array(1))
	}
        ...
}

There are a couple of class files, not relevant here. There’s another test file that I just started:


import org.junit._
import org.junit.runner._
import org.junit.runners._
import Assert._ 

class TestMore {
	@Test def hookup4 {
		assertEquals(4,4)
	}
}

As soon as I started with that, I realized I wanted a suite, to run everything. I have that in place, like this:


import org.junit._
import org.junit.runner._
import org.junit.runners._
import Assert._ 

@RunWith(classOf[Suite])
@Suite.SuiteClasses(Array(classOf[TestDummy]))
class TestEverything

class TestDummy {
	@Test def hookup {
		
	}
}

This is lifted from a couple of examples I found on the Web. I’ve fiddled a bit with what is in the RunWith class, and what is in the SuiteClasses array. None of them seems to work unless I have at least a dummy test in the same file, and I seem to require the empty class (TestEverything) as well.

As this stands, all the tests run and show green or red as they should. JUnit’s Eclipse GUI looks like this:

Notice that TestDummy shows up twice, once in the top-level listing where the other tests are. But at that level TestDummy does not have green check marks. It shows up again, under TestEverything, and there it will have checks as appropriate. I’ve fiddled with not having any tests in the TestEverything file, and that seems to fail entirely. I’ve tried various names, or putting the names of the other test classes in the @Suite entry. In every case, I either get errors or an odd display where some of the classes show up twice, on their own or under TestEverything.

Advise me, please … have you a configuration of JUnit with Scala with Suites? I’d love to see how it works.

And OK, let me know what testing tool you’re using with Scala as well. But I’m not going to get a Mac.

Thanks!