Apache Jakarta and Beyond: A Java Programmeramp;#039;s Introduction [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Apache Jakarta and Beyond: A Java Programmeramp;#039;s Introduction [Electronic resources] - نسخه متنی

Larne Pekowsky

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







7.1. Using JMeter


JMeter is not only a testing framework but also a sophisticated GUI for constructing tests. After running jmeter on Unix or jmeter.bat on Windows the user will be presented with the screen in Figure 7.1.


Figure 7.1. The JMeter startup screen.

[View full size image]

Tests are organized in units called test plans, not be confused with the human QA activities that are a part of development projects and that are also called test plans. JMeter test plans are constructed by adding elements to the framework, which is done through the "add" option of the "edit" menu, as shown in Figure 7.2.


Figure 7.2. The JMeter add menu.

[View full size image]

This process begins by adding a

thread group, which is an entity that maintains a set of threads. Each thread will independently run the entire test suite and will look like a separate client to the server being tested. This is the simplest way that JMeter provides load testing; it can simulate many independent clientsas many as the client machine and Java virtual machine can handle. The thread group configuration screen is shown in Figure 7.3.


Figure 7.3. The thread group configuration.

[View full size image]

Here it is specified that five threads are to be started, and each one should run the tests ten times. It is also possible to run the tests indefinitely by clicking "forever." The ramp-up time indicates how long it will take to start all the threads. The value of one second provided here means that each thread will be started one-fifth of a second after the previous one.

Now that the thread group has been defined, it is possible to specify what each thread should do, which is also done through the "Add" menu. This menu is context-sensitive and will present valid options based on the selected element in the left frame. Although the entries change, the overall look does not, and so the menu will not be shown again.

The simplest way to add a test is to add a

sampler to the thread group. Samplers may be thought of as individual clients; they are objects that make a request to a server. Many kinds of samplers are available, including ones to test Web servers, databases, and FTP servers. The configuration screen for the sampler that tests Web servers is shown in Figure 7.4.


Figure 7.4. The HTTP sampler configuration.

Listing 5.3. Note that the sampler itself does not test anything; it simply requests the page. The testing is done by another element called an

assertion, many kinds of which are provided. There is a duration assertion that requires a response within a specified time. There is also a size assertion that requires that the response contains a specified number of bytes. Finally, there is a response assertion that can look through the response for a pattern or patterns. Any combination of these can be used; it would be possible to require that a Web application responds quickly, that the response is the correct length, and that the response contains an expected string.

Assertions are added to samplers through the "Add" menu, and the configuration screen for the response assertion is shown in Figure 7.5.


Figure 7.5. The response configuration.

Listing 5.6. The combination of the sampler and the assertion will request the first page of the calculator and ensure that the string "Hello" is present.

This may seem to be much easier than writing an HTTPUnit class, but it is important to keep in mind that JMeter and HTTPUnit tests have different goals. HTTPUnit is meant to ensure that a page works as expected and to perform this check as quickly as possible so that it may be run often. Conversely the JMeter test is meant to ensure that the page continues to work properly and respond quickly under extended heavy load and must be run over a long period of time in order to get accurate results. Both kinds of test are important, and HTTPUnit and JMeter should therefore be thought of as complimentary.

Another important difference is that JMeter makes no attempt to provide a browser-like environment. It is possible to test form-driven pages, but it is not as straightforward as obtaining an object representing the form, filling it in, and submitting it. Instead, form parameters must be manually provided to the URL being tested. For example, page three of the calculator could be tested by providing values for number1 and number2 in another sampler, as shown in Figure 7.6. This sampler will use a response assertion to check that "59" appears on the resulting page.


Figure 7.6. Testing the result of the form.

[View full size image]

The final ingredient is a means to monitor the results, which JMeter calls a

listener. Listeners can be attached to many points within a test plan. Attaching a listener to a sampler will display the results for that sampler only, whereas attaching a listener to a thread group will merge the results from all samplers.

Once the listener has been defined, the test can be started from the "Run" menu. The results are then displayed by the listener, as shown in Figure 7.7.


Figure 7.7. The test results.


/ 207