Using scalacheck testing all permutations without coding it

Scalacheck is very cool, it will run all permutations against your code without you coding them!

here is how to run it with junit and maven:

           
                org.scalacheck
                scalacheck_2.9.2
                1.10.1
                test
           

Example unit test with junit

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class Test extends FunSuite with GeneratorDrivenPropertyChecks {
  test("t2") {
    forAll { (a: String, b: String) =>
      assert((a + b).startsWith(a))
    }
  }
}

result will look as following:

 Testing started at 8:27 PM ...
- t2
Process finished with exit code 0

Comments