binding and closures groovy
问题 I don't know how to use binding with closures in Groovy. I wrote a test code and while running it, it said, missing method setBinding on the closure passed as parameter. void testMeasurement() { prepareData(someClosure) } def someClosure = { assertEquals("apple", a) } void prepareData(testCase) { def binding = new Binding() binding.setVariable("a", "apple") testCase.setBinding(binding) testCase.call() } 回答1: This works for me with Groovy 1.7.3: someClosure = { assert "apple" == a } void