I want to write JMeter requests in Java. I found some examples by googling but I am not understanding how to assert the response i.e. the way we use Response Assertion to check whether the page was loaded successfully or not. Please share step-by-step process for JMeter with java coding.

  • Something like this masudqa.blogspot.com/2014/06/… ? – demouser123 Aug 11 '15 at 2:22
  • This style question is unlikely to produce quality answers. Instead, make an attempt and let us know what fails. And at this point if it's still a problem, might want to make a new question too. =) – corsiKa Jan 8 '16 at 16:35

You can take a look at 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide to learn how to run existing JMeter test scenario from Java code and how to create a JMeter test purely in Java.

Also refer jmeter-from-code snippet for working example.

In regards to implementing assertions, you can create a simple test plan i.e. having one request and one assertion, load it via SaveService.loadTree() method and inspect resulting HashTree to see how does it look under the hood.

|improve this answer|||||
  • Very interesting link. It is a bit annoying (probably I am missing it) that there are around the web quite a few ways about how to prepare and run testplans but there is not much about how to get the results if you are trying to use the Java API for JMeter. I understand this might be quite a specific need. – Giuseppe May 16 '19 at 14:32

Please refer the below link. Thought this might work. https://javaworks.wordpress.com/2013/06/28/beanshell-assertion-in-jmeter/

|improve this answer|||||
  • Thanks for your answer @SundarsCorp, But I want with pure java code – QAMember Jun 10 '15 at 14:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.