2

Is it possible to get assertion failed in tree view listener using this line of code in JSR223 Assertion?

assert 1 == 2

Before in JMeter version 3.1 i could do this without any problem and now its just not working. I know i can use these lines of code

if(1 != 2) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('They are not equal') }

but i would, if possible, like to keep it simpler and shorter like before, with just one line of code

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
kako lako
  • 33
  • 2

2 Answers2

2

Using assert will be possible in next 4.0 version as per:

You can try jmeter nighlty build:

I don’t think it was possible to do that in 3.1

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • Thank you UBIK LOAD PACK, this is the answer i was looking for. By the way it was working in 3.1 version, i can confirm this. I have all three versions opened and run same code, in 3.1 its working in 3.2 and 3.3 its not working – kako lako Dec 29 '17 at 10:47
0

I do confirm it is possible to use the above code for failing a sampler in JMeter 3.3 (latest version as of now)

JMeter 3.3 Groovy Response Assertion

Make sure that:

  1. The sampler you want to fail is located somewhere in the Assertion Scope
  2. You have groovy-all.jar in JMeter Classpath
  3. There are no any suspicious entries in jmeter.log file
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Hi Dmitri, thank you for your reply but it didnt answer the question. I know using IF and AssertionResult i can get code failing, but is it possible to do it with only one line of code like before and that is **assert 1 == 2** ? – kako lako Dec 29 '17 at 08:33
  • Using groovy [assert keyword](http://docs.groovy-lang.org/next/html/documentation/core-testing-guide.html#_power_assertions) won't fail your sampler, the only thing you will get is the message in *jmeter.log* file, if you're looking for a simplified "one line" solution for whatever reason use something like `if (1 != 2) throw new Exception('They are not equal')`. More information: [Scripting JMeter Assertions in Groovy - A Tutorial](https://www.blazemeter.com/blog/scripting-jmeter-assertions-in-groovy-a-tutorial) – Dmitri T Dec 29 '17 at 09:09
  • Thank you Dmitri, i really appreciate your answer, i will use the way of writhing it that you showed until 4.0 version when hopefully jmeter will be back on simple assert keyword – kako lako Dec 29 '17 at 10:41