Reputation: 1070
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:
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!
Upvotes: 4
Views: 3013
Reputation: 168002
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:
debug();
as a first line of your Beanshell script will trigger debugging output to stdoutBy 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
Upvotes: 3