我正在尝试创建几个库并调用它们。我的目标是将第二个方法称为第一个方法。
例如,我创建了两个库library1
和library2
。
Library1代码
class LibraryScriptTest1 {
def log
def context
def testRunner
def library2
def LibraryScriptTest1(log, context, testRunner) {
this.log = log
this.context = context
this.testRunner = testRunner
library = testRunner.testCase.testSuite.project.testSuites["LibraryTestSuiteTest"]
module = library.testCases["LibraryTestCaseTest2"].testSteps["LibraryScriptTest2"]
module.run(testRunner, context)
this.library2 = context.library2
}
int add(int firstNumber, int secondNumber) {
return firstNumber + secondNumber
}
int multiply(int firstNumber, int secondNumber) {
return firstNumber * secondNumber
}
int divide(firstNumber, secondNumber) {
return this.library2.divide(firstNumber, secondNumber)
}
}
context.setProperty("library1", new LibraryScriptTest1(log, context, testRunner))
Library2代码:
class LibraryScriptTest2 {
def log
def context
def testRunner
def LibraryScriptTest2(log, context, testRunner) {
this.log = log
this.context = context
this.testRunner = testRunner
}
int substract(int firstNumber, int secondNumber) {
return firstNumber - secondNumber
}
int divide(int firstNumber, int secondNumber) {
return firstNumber / secondNumber
}
}
context.setProperty("library2", new LibraryScriptTest2(log, context, testRunner))
错误
但是我在library1
中遇到此错误:
groovy.lang.MissingPropertyException:没有此类属性:的库 类:LibraryScriptTest1可能的解决方案:第2行的library2错误: XX
对应的行是下一行:
context.setProperty("library1", new LibraryScriptTest1(log, context, testRunner))
任何人都可以帮助我理解和解决该问题吗?谢谢。