JMeter Testing the JAVA interface

Source: Internet
Author: User

Using JMeter to test the Java interface, you need to write a Java class, inherit abstractjavasampleclient, implement a call to the specific interface, and then package the project as a jar package to prevent it from being in the Jmeter_home\lib\ext directory. Then configure the call in the JMeter.

    • Writing Java classes, inheriting abstractjavasampleclient
    • Packaging jars
    • Place the jar package into the Jmeter_home\lib\ext directory
    • Configuration call in JMeter

1. Add dependencies

<Dependency>    <groupId>Org.apache.jmeter</groupId>    <Artifactid>Apachejmeter_java</Artifactid>    <version>2.7</version></Dependency>

2. Writing Java classes

 Public classAdsearchservicetestextendsabstractjavasamplerclient {Private StaticAdsearchservice Adsearchservice; Static{ApplicationContext ApplicationContext=NewClasspathxmlapplicationcontext ("Applicationcontext.xml"); Adsearchservice= Applicationcontext.getbean ("Adsearchservice", Adsearchservice.class); } @Override Publicsampleresult runtest (Javasamplercontext javasamplercontext) {Sampleresult Sampleresult=NewSampleresult (); String keyword= Javasamplercontext.getparameter ("keyword"); Adsearchservice.param Param=NewAdsearchservice.param ();        Param.setkeyword (keyword); Param.setstart (1); Param.setlimit (10); Searchapiresult Kievresult=adsearchservice.search (param); Sampleresult.setresponsedata (Kievresult.getjson (),"Utf-8"); returnSampleresult; }     Public Static voidMain (string[] args) {adsearchservicetest Kiev=Newadsearchservicetest (); Arguments Arguments=NewArguments (); Arguments.addargument ("Keyword", "" "); Javasamplercontext Context=Newjavasamplercontext (arguments); Sampleresult result=kiev.runtest (context); System.out.println (NewString (Result.getresponsedata ())); }}

3. Packaging, packaging the dependent packages should be packaged together, otherwise the class can not find errors.

4. Place the jar package in the Jmeter_home\lib\ext directory

5. Configure JMeter

JMeter Testing the JAVA interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.