您不需要def
s 和@Test
注释。这是一个例子:
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.ShouldMatchersForJUnit
@RunWith(classOf[JUnitRunner])
class SpelHelperSpec extends FlatSpec with ShouldMatchersForJUnit {
"SpelHelper" should "register and evaluate functions " in {
new SpelHelper()
.registerFunctionsFromClass(classOf[Functions])
.evalExpression(
"#test('check')", new {}, classOf[String]) should equal ("check")
}
it should "not register non public methods " in {
val spelHelper = new SpelHelper()
.registerFunctionsFromClass(classOf[Functions])
evaluating { spelHelper.evalExpression("#testNonPublic('check')",
new {}, classOf[String]) } should produce [SpelEvaluationException]
}
}
资源