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

标签 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: 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$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*

最佳答案

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

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

关于api - 在 Groovy Soap UI 5.4.0 中执行类时出现 java.lang.InstantiationException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50579836/

相关文章:

ruby-on-rails - Rails 4.2如何在不同命名空间中遵循DRY原则?

api - 对于具有 GET 语义的超大请求应该使用什么 HTTP 动词?

asp.net - 理想的开发/测试/质量保证开发环境

unit-testing - TDD:您为单元测试公开了哪些方法?

python - 在 python 中使用 Web 服务的最佳方式是什么?

soap - 什么是整数数组的 WSDL 声明?

python - 如何在 Python 3 中通过 Flickr API 从 Flickr 下载照片

android - 当我开发Android应用程序时,我想在较低的Android版本中使用较高API的方法。怎么做?

javascript - Web 驱动器管理器正在关闭

php - WSO2 WSF/PHP 安装问题(需要 C 开发人员帮助)