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?