Getting started with JMeter Performance Testing

Source: Internet
Author: User

JMeter is a performance testing tool. I personally think that he is a tool rather than a framework. JMeter supports a wide range of applications that require performance testing, such as files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers ). One of the major advantages of JMeter is that it already has a well-implemented thread mechanism. You don't need to write anything about concurrency, but just need to make simple configuration. At the same time, this page provides something similar to plug-ins for controlling thread runtime. Secondly, JMeter can generate corresponding statistical reports for test results, which is simple and intuitive, it should be sufficient for general performance tests.

  1. QuickStart
    The downloaded JMeter has the following directories:Bin docs extras lib printable_docs. Bin does not need to be said. Run the following jmeter. bat to view the JMeter GUI client. You can configure all the tests. Below is all the user manuals of JMeter in docs, which are fairly detailed and can be found as needed. It is a pity that there are no Chinese characters. It takes more time to write English. In extras, JMeter supports Ant. It is not very specific, but the production report is essential. During the test, all test data can be recorded, and JMeter automatically generates a. jtl file. Put this file under extras and run ant-Dtest = file name report to generate the test statistical report. There are two directories in the lib directory, ext, which stores the user's test application for JMeter extension and junit Directory, which is useless and unclear. In the installation documentation, the ext directory stores the JMeter extension. the user's extension depends on the package directly under lib (not lib/ext ).
  2. Main plug-ins
    Thread groupAs the main plug-in of JMeter, many internal implementations are now available. You only need to add and configure the plug-in.

    The thread group configuration page is as follows:
     
    As shown in, you can configure the number of threads, the interval between the start of the previous thread and the next thread, and the number of cycles of the thread.

    Configuration element
    JMeter provides some basic configurations for all applications that can be used by JMeter.

     

    ListenerTo collect data during the test. You can also generate reports (text, graphics, etc.) based on the data)
     

    Logic ControllerUsed to control the running logic of a thread.
     

  3. Sample

    Here I use main JMeter threads and reports to extend the Application category of "Java requests. To expand this application, lib/ext/ApacheJMeter_java.jar is used to encapsulate this application.

    First, you must inherit the abstract class abstractpolicamplerclient in role. It provides four Abstract METHODS: void setupTest (abstramplercontext arg0), SampleResult runTest (abstramplercontext arg0), void teardownTest (abstramplercontext arg0 ), arguments getDefaultParameters (). SetupTest and teardownTest are similar to those in JUnit, which are executed at the start and end of the test respectively. RunTest is the main test method. All test programs are completed here. The parameter cyclamplercontext encapsulates all external data (such as configuration information) required in the test ). Its SampleResult encapsulates all test results (for example, is the test successful? Program execution time), getdefaparameparameters is used to display some of the test's default data to the JMeter client before the program runs, which can be used with runTest for data presentation and configuration.

    The program is as follows:

    Import org. apache. jmeter. config. Arguments;
    Import org. apache. jmeter. protocol. java. sampler. abstract=amplerclient;
    Import org. apache. jmeter. protocol. java. sampler. datagamplercontext;
    Import org. apache. jmeter. samplers. SampleResult;

    Import com. ebupt. wv. client. WVClient;

    Public class Login2 extends act1_amplerclient {

    Private static String label = "userLogin"
    Private String name;
    Private String address;

    Public void setupTest (JavaSamplerContext arg0 ){
    System. out. println ("setupTest ");
    }

    Public SampleResult runTest (datagamplercontext arg0 ){
    Name = arg0.getParameter ("name ");
    Address = arg0.getParameter ("address ");
    SampleResult sr;
    Sr = new SampleResult ();
    Sr. setSampleLabel (label );
    Try {
    Sr. sampleStart (); // record the program execution time and execution result
    Sr. setSuccessful (true );
    System. out. println ("send over! ");
    } Catch (Throwable e ){
    Sr. setSuccessful (false );
    } Finally {
    Sr. sampleEnd ();
    }
    Return sr;
    }

    Public void teardownTest (datagamplercontext arg0 ){
    }

    Public Arguments getDefaultParameters (){
    Arguments params = new Arguments ();
    Params. addArgument ("name", "JMeter ");
    Params. addArgument ("address", "localhost ");
    Return params;
    }

    }

    Next, package the written application and put it under lib/ext. You can find it at JMeter runtime. At the same time, you must place the packages on which your applications depend under lib. Run JMeter. After the interface is opened, right-click "test plan" and add a thread group. Right-click "thread group" and choose "Add-Sampler-Java request". Select the class you just wrote in the class name.

    Here, you can add multiple thread groups, multiple java requests, and a listener to output different test results and reports, each request can be controlled by a logical controller.

    Finally, click Run-start to save the corresponding project to start running. You can use the listener to write data during runtime to generate reports as needed.

  4. Ant use
    Before running the JMeter project, you will be asked to save the project as a. jmx file and put the file in the extras directory. ant can be used to automate the test. Ant has the following commands:
    Ant-Dtest = Project name: run the project and generate a report.
    Ant-Dtest = project name run only runs the project.
    Ant-Dtest = project name report only generates reports (the. jtl file recorded during the test must be put in the ant directory)

    The report is as follows:
     

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.