在Groovy Soap UI 5.4.0中执行类时出现java.lang.InstantiationException错误

时间:2018-05-29 08:36:14

标签: api testing soap groovy soapui

尝试在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:无法为类创建Script实例:class MyClass。原因: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$1.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$1.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*

1 个答案:

答案 0 :(得分:2)

创建一个Groovy Script测试步骤并拥有该类并调用该方法,如下所示:

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()