Sunday, April 12, 2009

ScalaTest IDE Support coming soon.

I've written something that allows me to write my tests in ScalaTest as normal (don't have to use any TestNG annotations in my tests), but also run them in all the IDE's, piggybacking off the TestNG IDE plugins. The code isn't in ScalaTest yet, but I'm guessing it likely will get in soon.

Until then, anyone using FunSuite can borrow this code and temporarily use MiniFunSuite instead. This all seems to work quite well.

Here's the client/test code:

class FunSuiteExample extends FunSuiteTestNGAdapter{
test("hey"){ println("hey") }
test("fail"){ assert( 1 === 2 ) }

And here's the library code:

import org.scalatest.testng.TestNGSuite
import org.testng.annotations.{DataProvider, Test}

trait MiniFunSuite{
var testMap = Map[String, Function0[Unit]]()
def test(name:String)(f: => Unit) = testMap += (name -> f _)

trait FunSuiteTestNGAdapter extends MiniFunSuite with TestNGSuite{

@DataProvider{ val name="tests" }
def tests ={ case (s,f) => Array(s,f) }.toList.toArray

@Test{ val dataProvider = "tests" }
def scalaTest(testName:String, f: => Unit) = { f }

1 comment:

  1. Jon-Anders TeigenApril 13, 2009 3:28 AM

    Nice work using test-ng.

    I did something similar a little while back, writing a junit4runner to run my scalatests from IDEs and Maven. It works with all the different test-traits in scalatest.