In JMeter, assertions are used to verify the correctness of the responses received from the server during performance testing. They allow you to set specific criteria or conditions that need to be met by the server response. If the assertion fails, the server response does not meet the specified criteria, indicating a problem or error in the application or server being tested.
JMeter provides various assertions that you can use based on your requirements. Let's try an example of Response Assertion.
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Main extends JFrame implements ActionListener { private JLabel labelQuestion; private JLabel labelWeight; private JTextField fieldWeight; private JButton buttonTellMe; public Main() { super("Water Calculator"); initComponents(); setSize(Toolkit.getDefaultToolkit().getScreenSize()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void initComponents() { labelQuestion = new JLabel("How much water should a person drink?"); labelWeight = new JLabel("My weight (kg):"); fieldWeight = new JTextField(5); buttonTellMe = new JButton("Tell Me"); setLayout(new FlowLayout()); add(labelQuestion); add(labelWeight); add(fieldWeight); add(buttonTellMe); buttonTellMe.addActionListener(this); } public void actionPerformed(ActionEvent event) { String message = "Buddy, you should drink %.1f L of water a day!"; float weight = Float.parseFloat(fieldWeight.getText()); float waterAmount = calculateWaterAmount(weight); message = String.format(message, waterAmount); JOptionPane.showMessageDialog(this, message); } private float calculateWaterAmount(float weight) { return (weight / 10f) * 0.4f; } public static void main(String[] args) { new Main().setVisible(true); } }
Note: Please proceed with the following steps once above widget gets started.
Once JMeter starts running, go to “File” → “Open” and navigate to the location where you saved the JMX file.
Select the JMX file and click “Open” to load the test plan into JMeter.
In the JMeter GUI, you'll see the test plan structure and configuration. Verify that all the components and settings are as desired.
Click the green “Play” button or go to “Run” → “Start” to start the test execution.
JMeter will start sending requests based on the configured settings. You can monitor the progress and view the results in real time using various listeners such as the “View Results Tree” or “Summary Report”.
Once the test execution is complete, you can analyze the results and performance metrics obtained from JMeter’s listeners and generate reports if needed.
After following all of the above steps, you must click on the exclamation mark in the top right corner, and you'll be able to see the logs at the bottom of the screen.
Free Resources