groovy - 从 Groovy 中的 setup 方法内部调用闭包/方法
问题描述
由于某种原因,setup 方法无法识别它之前的闭包,因为当这段代码被放入测试套件并运行时,它会抛出
MissingMethodException
我试图调用的闭包:
int initialNumberOfRows = 0
def findRowCount = {
initialNumberOfRows = 5
}
/**
* Some methods below are samples for using SetUp/TearDown in a test suite.
*/
/**
* Sets up test environment.
*/
@SetUp(skipped = false) // Please change skipped to be false to activate this method.
def setUp() {
// login and select the test company first
WebUI.callTestCase(findTestCase('Test Cases/TestCompanySelectGoesToDashboard'), [('shouldLogout') : false, ('shouldCloseBrowser') : false])
// go to the "Discounts" page
WebUI.click(findTestObject('PageMenuOptions/a_Discounts'))
// determine the row count
WebUI.delay(5)
findRowCount()
}
我运行该代码并收到以下异常消息:
groovy.lang.MissingMethodException: No signature of method: DiscountsSuite.findRowCount() is applicable for argument types: () values: []
截至目前,闭包是一个存根,但将用于获取行数,之后我们将删除作为测试套件的清理(我通过测试套件创建行,我必须清理它们! )
解决方案
推荐阅读
- go - GO111MODULE=on(错误加载模块要求)
- python-3.x - Python脚本停留在导入
- c# - C# - 定义泛型函数字典
- java - 在同一个流上重复 forEach() - 为什么不可能?
- java - 从 Firebase 实时数据库获取计数器值的问题
- c++ - 如何从文件中正确加载完整变量数据集的值?
- ios - 如何在 Swift 中修复“UIAlertController 的 ActionSheet 具有冲突约束”错误
- sql - CLR 程序集可能会给 SQL Server 实例带来安全漏洞
- javascript - 图表未水平对齐
- jpa - 使用 JPA 定义动态数据库配置