0
votes

I try to make a test that read from DB and assert the data I create a JDBC request and JSR223 sampler + Jsr223 assertion. in the sampler I created a variable called sensativity_results. and I want to pass it to the assertion. I used

vars.putObject("sensativity_results", sensativity_results);

and then in the assertion I try to call it and print it, the problem is that Jmeter just not recognized the assertion, Moreover I created another sampler called test to print the results of "sensativity_results" and Jmeter just pass it and not even execute it

int actual_sensativity ()
{
    float Actual_sensativity;
    int loop_num = vars.get("Loop_Number") as int; 
    int conversion_sense = vars.get("Conv_sens") as int;
    int actual_conversion = vars.get("Conv_numbers_1") as int;
    Actual_sensativity = (float) (actual_conversion/loop_num)*100;
    System.out.println("************** Actual_sensativity  in %:  " + Actual_sensativity);
    System.out.println("**conversion_sensativity:  " + conversion_sense);
    System.out.println("**actual_conversion:  " + actual_conversion);
    System.out.println("**loop number:  " + loop_num);
    return Actual_sensativity;

}




int sensativity_results;
sensativity_results = actual_sensativity();
vars.putObject("sensativity_results", sensativity_results);
System.out.println("sensativity_results:  " + sensativity_results);

the test plan ran as expected until this step and stopped without any error it print the sensitivity results at the first sampler, and just not move on, can someone please advise?

enter image description here enter image description here

enter image description here

enter image description here

enter image description here

2

2 Answers

0
votes

Just put vars.put("sensativity_results", sensativity_results); and it solved the issue

0
votes

Assuming you will be using this sensativity_results variable as a String later on I would suggest storing it like:

vars.put("sensativity_results", String.valueOf(sensativity_results))

Otherwise you will get ClassCastException: java.lang.Integer cannot be cast to java.lang.String error on attempt to use it like ${sensativity_results}

Alternative way of accessing non-String variables would be using __groovy() function (available since JMeter 3.1) like:

${__groovy(String.valueOf(vars.getObject('foo')),)}