jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: Adding Response Assertion to a Java Sampler
Date Wed, 20 Dec 2006 22:06:51 GMT
On 20/12/06, jmeter_user_2006 <it_krish@yahoo.com> wrote:
>
> Hi,
>
> I am trying to load test a Java application and would like to verify some
> results by applying a response assertion on the returned value.
>
> The code looks something liek this:
> ....
>  SampleResult results = new SampleResult();
OK

>             try {
>                 results.sampleStart();

OK - you also need a sampleEnd();

>
>                 String response = getResponseFromJavaApp();
>                 results.setSamplerData("\\[testCount 1\\]"); // what does this
> method do?

It sets the sampler data - i.e. the data that the sampler passed to
the external system.
It should be set before running the sample.

>                 ResponseAssertion assertion = new ResponseAssertion();
>                 assertion.setAssumeSuccess(false);
>                 assertion.setName("Assertion Results");
>                 assertion.setTestField(response);
>
>                 AssertionResult result = assertion.getResult(results);
>                 logger.debug("Failure message = " + result.getFailureMessage());
>
>                 AssertionResult[] ars =results.getAssertionResults();

Assertions are added as separate test elements, not as code in the sampler.

>                 results.setSampleLabel(response);
> ....
>
> I would like to know if my response contains the required text....how do I

Add an assertion in the test plan.

Or just use standard Java code.

> verify this? What is it that I am doing wrong in the code above/
> Any tips would be appreciated .


Have a look at some of the example samplers under src/examples.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Mime
View raw message