Integrating Scalacheck with Maven using TestNG

94 views
Skip to first unread message

Nate Bauernfeind

unread,
Dec 17, 2011, 11:53:18 PM12/17/11
to scala...@googlegroups.com
I saw some suggestions on how to integrate scalacheck with maven using JUnit. (Primarily by annotating Properties classes with @RunWith(classOf[JUnitRunner]))

However I had a much harder time (read: impossible) trying to get testng to run the test for me.

Eventually I slapped together this solution:
import org.scalacheck.{ConsoleReporter, Test, Properties}
import java.lang.AssertionError

class TestNGProperties(name: String) extends Properties(name) {
  @org.testng.annotations.Test
  def runner() {
    val params = Test.Params.apply(testCallback = ConsoleReporter(1))
    val res = Test.checkProperties(params, this)
    val failed = res.filter(!_._2.passed).size
    if (failed > 0) throw new AssertionError(name + " has failed properties.")
  }
}

Every specification simply has to extend TestNGProperties and be annotated with @Test from TestNG.

I wanted to post this to 1) offer a possible solution and 2) find out if there's a better known solution.

Bill Venners

unread,
Dec 18, 2011, 5:42:31 AM12/18/11
to scala...@googlegroups.com
Hi Nate,

You could use TestNGSuite and either Checkers or PropertyChecks from ScalaTest:

http://scalatest.org/scaladoc/1.6.1/#org.scalatest.testng.TestNGSuite

http://scalatest.org/scaladoc/1.6.1/#org.scalatest.prop.Checkers

http://scalatest.org/scaladoc/1.6.1/#org.scalatest.prop.PropertyChecks

Bill

> --
> You received this message because you are subscribed to the Google Groups
> "scalacheck" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/scalacheck/-/bMHHnYNB6hAJ.
> To post to this group, send email to scala...@googlegroups.com.
> To unsubscribe from this group, send email to
> scalacheck+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/scalacheck?hl=en.

--
Bill Venners
Artima, Inc.
http://www.artima.com

Reply all
Reply to author
Forward
0 new messages