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]

Figure 7.2. The JMeter add menu.
[View full size image]

Figure 7.3. The thread group configuration.
[View full size image]

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]
