mockTest( "Report should be generated for each invocation" ){
val reporter = mock(classOf[Reporter])
expecting( "reporter gets 10 passing reports because invocationCount=10" ) {
nTestsToPass( 10, reporter )
}
when ( "run the suite with method that has invocationCount=10" ){
new TestNGSuiteWithInvocationCount().runTestNG(reporter)
}
}
mockTest( "Reporter should be notified when test is skipped" ){
val reporter = mock(classOf[Reporter])
expecting ( "a single test should fail, followed by a single test being skipped" ){
one(reporter).runStarting(0)
one(reporter).testStarting(any(classOf[Report]))
one(reporter).testFailed(any(classOf[Report]))
one(reporter).testIgnored(any(classOf[Report]))
one(reporter).runCompleted()
}
when ( "run the suite with a test that should fail and a test that should be skipped" ){
new SuiteWithSkippedTest().runTestNG(reporter)
}
}
As you can see, I've added expecting and when blocks, which optionally take a String (that is currently just used for readability). The simple idea here is that I have grouped chunks of my test into places that make sense, hopefully making it easier for someone reading the test. Do you like it? Do you hate it? Any other opinions that could help?
I like it. Would be fun to play around with a bit.
ReplyDeleteIs the code available somewhere?
Have you looked at the specify() {..} methods in ScalaTest trunk?
/Jonas
Sorry I haven't gotten back to you sooner. The code is in trunk, but since its still experimental, we've left it in the test area. You can find it in app/tests/org/scalatest/jmock. I used it to write most of my tests for the Scalatest/TestNG integration, and you can find examples of that in app/tests/org/scalatest/testng.
ReplyDeleteThe path for the mocking stuff will most definitely change soon.
As for the specify methods, I was somewhat familiar with them, but I'm not sure they exist anymore. Can you refresh my memory on them?