groovy的脚本置于idea中进行调试,报如下错误:
java.lang.UnsupportedOperationException at net.grinder.scriptengine.groovy.junit.GrinderRunner.withBeforeProcess(GrinderRunner.java:268) at net.grinder.scriptengine.groovy.junit.GrinderRunner.classBlock(GrinderRunner.java:207) at net.grinder.scriptengine.groovy.junit.GrinderRunner.run(GrinderRunner.java:169) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 版本: groovy: 2.4.9 idea: IntelliJ IDEA 2016.2.5 Build #IU-162.2228.15, built on October 14, 2016 Licensed to lan yu Subscription is active until October 14, 2018 JRE: 1.8.0_112-release-287-b2 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o |
补充JDK版本:
java version "1.8.0_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode) |
In reply to this post by defias
补充完整的脚本:
import static net.grinder.script.Grinder.grinder import static org.junit.Assert.* import static org.hamcrest.Matchers.* import net.grinder.plugin.http.HTTPRequest import net.grinder.plugin.http.HTTPPluginControl import net.grinder.script.GTest import net.grinder.script.Grinder import net.grinder.scriptengine.groovy.junit.GrinderRunner import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread // import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3 import org.junit.Before import org.junit.BeforeClass import org.junit.Test import org.junit.runner.RunWith import java.util.Date import java.util.List import java.util.ArrayList import HTTPClient.Cookie import HTTPClient.CookieModule import HTTPClient.HTTPResponse import HTTPClient.NVPair /** * A simple example using the HTTP plugin that shows the retrieval of a * single page via HTTP. * * This script is automatically generated by ngrinder. * * @author admin */ @RunWith(GrinderRunner) class TestRunner { public static GTest test public static HTTPRequest request public static NVPair[] headers = [] public static NVPair[] params = [] public static Cookie[] cookies = [] @BeforeProcess public static void beforeProcess() { HTTPPluginControl.getConnectionDefaults().timeout = 6000 test = new GTest(1, "lq.xxxx.xxxxx") request = new HTTPRequest() // Set header datas List<NVPair> headerList = new ArrayList<NVPair>() headerList.add(new NVPair("Content-Type", "application/x-www-form-urlencoded")) headers = headerList.toArray() // Set param datas List<NVPair> paramList = new ArrayList<NVPair>() paramList.add(new NVPair("page_num", "5")) paramList.add(new NVPair("page_size", "3")) paramList.add(new NVPair("user_info", "{ \"user_id\": 4528232762800116557, \"user_name\": \"E078014212\", \"app\": 1223}")) paramList.add(new NVPair("app", "3")) params = paramList.toArray() grinder.logger.info("before process."); } @BeforeThread public void beforeThread() { test.record(this, "test") grinder.statistics.delayReports=true; grinder.logger.info("before thread."); } @Before public void before() { request.setHeaders(headers) cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) } grinder.logger.info("before thread. init headers and cookies"); } @Test public void test() { HTTPResponse result = request.POST("http://lq.xxx-xxx:8293/auth/resource/getdatafieldlist", params) if (result.statusCode == 301 || result.statusCode == 302) { grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode); } else { assertThat(result.statusCode, is(200)); } } } |
Free forum by Nabble | Edit this page |