3
votes

I am learning into Jmeter.

I have a BeanShell Assertion which should make the tests fail (failure is hardcoded into the assertion). But all the tests pass. What am I doing wrong?

My understanding is that if the BSA sets

Faliure = true;

the assertion fails. But in my case it does not fail.

Please see:

Assertion

Result

You can see the disabled XPath Assertion on the screenshot which is not fulfilled, if I enable that one, that one does fail the test as I expect.

Update: now I see why it didn't fail the tests: Failure has a typo... Then the question: Why did it even run? Isn't this java? Isn't this an undeclared variable?

Thank you!

1

1 Answers

3
votes

You have 2 typos, correct statements are:

Failure = true;
FailureMessage = "Here goes the failure message";

Assertion is successful as the code is fine from Beanshell perspective, in Beanshell you don't need to explicitly define object class. As long as it is valid code - your assertion is successful.

Here is a couple of troubleshooting techniques:

  1. Adding debug(); as a first line of your Beanshell script will trigger debugging output to stdout
  2. By surrounding your code in try/catch block like:

    try {
        //your code here
    }
    catch (Throwable ex) {
        log.error("Failure", ex);
        throw ex;
    }
    

    you will have the relevant stacktrace printed to jmeter.log file

See How to Use BeanShell: JMeter's Favorite Built-in Component article for comprehensive information on using Beanshell test elements in JMeter