Search code examples
jmeterassertions

How to verify in JMeter that specific variable set by JDBC Request is higher than 0?


I created JMeter test when I use JDCB query which returns NUMBER value which I set to variable e.g. called employeeID.

I know that it is possible to use Response Assertion and I can verify if my variable: employeeID_1 is equal to specific expected value.

How can I verify if my variable is > 0 instead?


Solution

  • The most straight forward would be using BeanShell Assertion like this:

    int myNumber = -1;
    
    try {
        myNumber = Integer.parseInt(vars.get("employeeID_1"));
    } catch(NumberFormatException e)
    { /* Continue to verification with default value */ }
    
    if(myNumber <= 0) {
        Failure = true;
        FailureMessage = "Expected value to be above 0, but got " + myNumber;
    }