JMeterを使用してRESTfulWebサービスを呼び出す方法は? 単純な負荷テストと自動化を実行する
公開: 2018-02-12Representational State Transfer(REST)は、SOAPおよびWebサービス記述言語(WSDL)ベースのWebサービスのより単純な代替手段として、Web全体で広く受け入れられています。
このインターフェース設計の変化の主な証拠は、Yahoo、Google、Facebookなどの主流のWeb 2.0サービスプロバイダーがRESTを採用していることです。これらのプロバイダーは、SOAPおよびWSDLベースのインターフェースを廃止または受け継いでおり、使いやすく、サービスを公開するためのリソース指向モデル。 RESTFulWebサービスをテストする必要がある場合があります。 いくつかのオプションがあります。
- 単一のURLを使用してWebサービスにアクセスします
JMeter
を使用して、ループ内でWebServiceをヒットします。 このテストでは、いくつかの単純なLoad Test
テストも実行されます。
この例では、JMeterを使用してSimple Hello World WebService
を作成し、同じWebServiceをヒットする方法について説明します。
以下の質問のいずれかがある場合、あなたは正しい場所にいます:
- JMeterを使用したSOAP / RESTWebサービスのテスト
- JMeterを使用したRESTfulAPIのパフォーマンステスト
- JMeterでのRESTAPI自動化–パフォーマンステスト
- JMeterを使用してRESTAPIをテストする方法
- JMeterを使用してRESTfulWebサービスをテストする(Jersey)
アクションの概要:
-
Pre-Requisite:
このRESTFulサービスを完全に実装します。 - 単純なJavaクラスを作成します:CrunchifyJMeterTest.java(JMeterを使用してヒットするサービス)。
- 同じアプリケーションをApacheTomcatWebサーバーに再デプロイします。
- JMeterを実行し、以下の提供され
.jmx
ファイルを開きます - テストを実行して分析する
別の人は読む必要があります:
- SOAPとREST:シンプルオブジェクトアクセスプロトコルと代表的なStateTransfer
ステップ1
Pre-Requisite:
このRESTFulサービスを完全に実装します。 アプリケーションをデプロイして実行します。
問題が発生した場合はお知らせください。
ステップ2
CrunchifyJMeterTest.java
ファイルを作成します
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package com . crunchify . restjersey ; import java . io . FileNotFoundException ; import java . io . IOException ; import javax . ws . rs . GET ; import javax . ws . rs . Path ; import javax . ws . rs . Produces ; /** * @author Crunchify * */ @ Path ( "/index" ) public class CrunchifyJMeterTest { @ GET @ Produces ( "text/html" ) public String checkECV ( ) throws InterruptedException , FileNotFoundException , IOException { String result = "<br><div align='center'><h2>Hey This is Crunchify's JMeter Test...</h2></div>" ; System . out . println ( result ) ; Thread . sleep ( 1000 ) ; return result ; } } |
以下にEclipseディレクトリ構造が表示されます。
ステップ-3
同じCrunchifyRESTJerseyExampleプロジェクトをTomcatに再デプロイします。 RESTサービスをテストしてください。
URL:
http:// localhost:8080 / CrunchifyRESTJerseyExample / crunchify / index /
ステップ-4
以下のコードをファイルにコピーし、 Crunchify-JMeter-Test.jmx
として保存します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
<? xml version = "1.0" encoding = "UTF-8" ?> < jmeterTestPlan version = "1.2" properties = "2.4" jmeter = "2.9 r1437961" > < hashTree > < TestPlan guiclass = "TestPlanGui" testclass = "TestPlan" testname = "App Shah Desktop Test" enabled = "true" > < stringProp name = "TestPlan.comments" > < / stringProp > < boolProp name = "TestPlan.functional_mode" > false < / boolProp > < boolProp name = "TestPlan.serialize_threadgroups" > false < / boolProp > < elementProp name = "TestPlan.user_defined_variables" elementType = "Arguments" guiclass = "ArgumentsPanel" testclass = "Arguments" testname = "User Defined Variables" enabled = "true" > < collectionProp name = "Arguments.arguments" / > < / elementProp > < stringProp name = "TestPlan.user_define_classpath" > < / stringProp > < / TestPlan > < hashTree > < ThreadGroup guiclass = "ThreadGroupGui" testclass = "ThreadGroup" testname = "Crunchify's REST Service JMeter Test" enabled = "true" > < stringProp name = "ThreadGroup.on_sample_error" > continue < / stringProp > < elementProp name = "ThreadGroup.main_controller" elementType = "LoopController" guiclass = "LoopControlPanel" testclass = "LoopController" testname = "Loop Controller" enabled = "true" > < boolProp name = "LoopController.continue_forever" > false < / boolProp > < intProp name = "LoopController.loops" > - 1 < / intProp > < / elementProp > < stringProp name = "ThreadGroup.num_threads" > 5 < / stringProp > < stringProp name = "ThreadGroup.ramp_time" > 2 < / stringProp > < longProp name = "ThreadGroup.start_time" > 1367432020000 < / longProp > < longProp name = "ThreadGroup.end_time" > 1367432020000 < / longProp > < boolProp name = "ThreadGroup.scheduler" > false < / boolProp > < stringProp name = "ThreadGroup.duration" > < / stringProp > < stringProp name = "ThreadGroup.delay" > < / stringProp > < / ThreadGroup > < hashTree > < HTTPSamplerProxy guiclass = "HttpTestSampleGui" testclass = "HTTPSamplerProxy" testname = "HTTP Request" enabled = "true" > < boolProp name = "HTTPSampler.postBodyRaw" > true < / boolProp > < elementProp name = "HTTPsampler.Arguments" elementType = "Arguments" > < collectionProp name = "Arguments.arguments" > < elementProp name = "" elementType = "HTTPArgument" > < boolProp name = "HTTPArgument.always_encode" > false < / boolProp > < stringProp name = "Argument.value" > < / stringProp > < stringProp name = "Argument.metadata" > = < / stringProp > < / elementProp > < / collectionProp > < / elementProp > < stringProp name = "HTTPSampler.domain" > localhost < / stringProp > < stringProp name = "HTTPSampler.port" > 8080 < / stringProp > < stringProp name = "HTTPSampler.connect_timeout" > 10000 < / stringProp > < stringProp name = "HTTPSampler.response_timeout" > 10000 < / stringProp > < stringProp name = "HTTPSampler.protocol" > < / stringProp > < stringProp name = "HTTPSampler.contentEncoding" > < / stringProp > < stringProp name = "HTTPSampler.path" > / CrunchifyRESTJerseyExample / crunchify / index < / stringProp > < stringProp name = "HTTPSampler.method" > GET < / stringProp > < boolProp name = "HTTPSampler.follow_redirects" > true < / boolProp > < boolProp name = "HTTPSampler.auto_redirects" > false < / boolProp > < boolProp name = "HTTPSampler.use_keepalive" > true < / boolProp > < boolProp name = "HTTPSampler.DO_MULTIPART_POST" > false < / boolProp > < boolProp name = "HTTPSampler.monitor" > false < / boolProp > < stringProp name = "HTTPSampler.embedded_url_re" > < / stringProp > < / HTTPSamplerProxy > < hashTree / > < ResultCollector guiclass = "StatGraphVisualizer" testclass = "ResultCollector" testname = "Aggregate Graph" enabled = "true" > < boolProp name = "ResultCollector.error_logging" > false < / boolProp > < objProp > < name > saveConfig < / name > < value class = "SampleSaveConfiguration" > < time > true < / time > < latency > true < / latency > < timestamp > true < / timestamp > < success > true < / success > < label > true < / label > < code > true < / code > < message > true < / message > < threadName > true < / threadName > < dataType > true < / dataType > < encoding > false < / encoding > < assertions > true < / assertions > < subresults > true < / subresults > < responseData > false < / responseData > < samplerData > false < / samplerData > < xml > true < / xml > < fieldNames > false < / fieldNames > < responseHeaders > false < / responseHeaders > < requestHeaders > false < / requestHeaders > < responseDataOnError > false < / responseDataOnError > < saveAssertionResultsFailureMessage > false < / saveAssertionResultsFailureMessage > < assertionsResultsToSave > 0 < / assertionsResultsToSave > < bytes > true < / bytes > < / value > < / objProp > < stringProp name = "filename" > < / stringProp > < / ResultCollector > < hashTree / > < ResultCollector guiclass = "StatVisualizer" testclass = "ResultCollector" testname = "Aggregate Report" enabled = "true" > < boolProp name = "ResultCollector.error_logging" > false < / boolProp > < objProp > < name > saveConfig < / name > < value class = "SampleSaveConfiguration" > < time > true < / time > < latency > true < / latency > < timestamp > true < / timestamp > < success > true < / success > < label > true < / label > < code > true < / code > < message > true < / message > < threadName > true < / threadName > < dataType > true < / dataType > < encoding > false < / encoding > < assertions > true < / assertions > < subresults > true < / subresults > < responseData > false < / responseData > < samplerData > false < / samplerData > < xml > false < / xml > < fieldNames > false < / fieldNames > < responseHeaders > false < / responseHeaders > < requestHeaders > false < / requestHeaders > < responseDataOnError > false < / responseDataOnError > < saveAssertionResultsFailureMessage > false < / saveAssertionResultsFailureMessage > < assertionsResultsToSave > 0 < / assertionsResultsToSave > < bytes > true < / bytes > < / value > < / objProp > < stringProp name = "filename" > < / stringProp > < / ResultCollector > < hashTree / > < / hashTree > < / hashTree > < / hashTree > < / jmeterTestPlan > |

ステップ-5
- ApacheJMeterをダウンロードします。
- jmeter.batまたはjmeter.shファイルを使用してJMeterを実行します
- [
File -> Open
をクリックします - ファイルCrunchify-JMeter-Test.jmxを保存したフォルダーに移動し、ファイルを選択します
ステップ-6
- 次の画像に示すように、CrunchifyのRest Service JMeterTestを展開します。
- HTTPリクエストをクリックします
- 以下のパラメータが正しいことを確認してください
ステップ-7
テスト結果を分析します。
JMeterでAPI自動化を休ませますか?
さて、各開発サイクルの後に、特定の間隔でJMeterファイルですでに定義したテストを実行できます。
テストパラメータを変更する方法は他にもたくさんあります。 それで遊んで、それがどうなるか、またはこれに問題があれば教えてください。