java.lang.InstantiationException 在 Groovy Soap UI 5.4.0 中执行 class 时出错

java.lang.InstantiationException error when executing class in Groovy Soap UI 5.4.0

尝试在 SOAPUI 5.4.0 中执行 Groovy 脚本

class MyClass {
// The three following fields are MANDATORY
def log 
def context
def testRunner

public  MyClass(log,context,testRunner){
    this.log = log 
    this.context = context
    this.testRunner = testRunner
    }
    def MyMethod(){log.info "Reference Groovy function file" }
}

class Call{

MyClass myClass = new MyClass();
myClass.MyMethod();

}

和接收错误,即

groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class MyClass. Reason: java.lang.InstantiationException: MyClass

相同的代码在以前的 soap ui 版本中有效,请你帮忙。

错误堆栈

*Tue May 29 15:43:08 IST 2018:ERROR:cannot get error line number!
Tue May 29 15:43:08 IST 2018:ERROR:java.lang.IllegalStateException: No match found
   java.lang.IllegalStateException: No match found
    at java.util.regex.Matcher.group(Matcher.java:536)
    at com.eviware.soapui.support.GroovyUtils.extractErrorLineNumber(GroovyUtils.java:128)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:163)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Tue May 29 15:43:08 IST 2018:ERROR:groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class MyClass. Reason: java.lang.InstantiationException: MyClass
   groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class MyClass. Reason: java.lang.InstantiationException: MyClass
    at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:464)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:706)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:742)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:733)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:136)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:87)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
   Caused by: java.lang.InstantiationException: MyClass
    at java.lang.Class.newInstance(Class.java:427)
    at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:436)
    ... 10 more
   Caused by: java.lang.NoSuchMethodException: MyClass.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.newInstance(Class.java:412)
    ... 11 more*

创建一个 Groovy 脚本测试步骤并具有 class 并调用如下脚本所示的方法:

class MyClass {
    def log 
    def context
    def testRunner

    def myMethod(){
        log.info "Reference Groovy function file" 
    }
}

//Call above class method as below
def myClassObject = [log: log, context: context, testRunner: testRunner] as MyClass
myClassObject.myMethod()