Hi there, I recently became aware of an amazing debugging feature in Jetbrains IDE’s that has made my debugging workflows so much easier and fast. They are called as Conditional breakpoints
Often while developing tests you might want the debugger to pause only when a specific condition happens.
We know we can always put a breakpoint on any line or function call and run our test in debug mode and then use the debugger to step into/step over, etc till we reach the point where we want to debug from.
However many times, this can become tedious quite quickly if you have many rows of data in your data-driven test as you need to press continue till you reach the row/record which are you interested in.
Conditional breakpoints provide a quick way to work around this problem.
Let’s see how
To show this in action, I will assume a test program which given a number
num determines if it is a prime or not and a simple test for this.
Let’s assume we want to debug something when the value of
3 (this could be replaced with any condition that you care about in your program)
You can click on the line no (in this case
12 in below screenshot) to add a breakpoint as you normally do. But if you right click on the breakpoint then you can see the option to add a condition. Any condition that you add here would get evaluated every time the program flow comes to this line and if the condition evaluates to a true and only then would the breakpoint would get triggered.
As you can see below, the program breaks when the condition matches.
This is very useful and is available in all the IDE’s provided by Jetbrains. With this debugging feature, I can easily make the debugger stop at the condition that I can about, without changing the code/test data that’s feeding into the method. Go ahead try it, You will wonder how you even debugged earlier without this feature.