Forum Discussion

mmoser18's avatar
mmoser18
Frequent Contributor
9 years ago
Solved

How to debug regular expressions in soapUI?

To allow more flexible testing I am trying to define misc. regular expressions that our received responses have to match. However, I am having some severe trouble getting this to work in soapUI. 

 

Since my regular expressions are somewhat huge all attempts to debug them within soapUI turned out to be hopeless. Just getting a thumbs up/down response is not enough to debug a more complex regexp when applying them to pretty large received response.

 

So I changed my approach and I am now not entering the regex itself into the assertion field but rather a small piece of code that reads the regex from a file and then uses that to verify the received response.

That allows me to develop and debug my regex using misc. tools (the best of which for me turned out to be RegexBuddy btw.)

 

Thus my assertion script (a bit simplified) looks like this:

 

def rulename = 'rulename'
def path = "some_path/"

# read the regexp from a file: def pattern = new File(path + rulename + ".pattern").getText('UTF-8') # get the response def response = messageExchange.response.responseContent

# assert that the response satisfies the regex: assert response =~ pattern

 

That approach is indeed working nicely, at least if things are simple. But for more complex rules I have now bumped into several cases, where some legal responses are accepted, but others are not, even though they SHOULD match!

 

Annoyingly, when I feed the same rule and both, matching and not-matching responses to RegexBuddy, then they both are accepted. So, somehow the exact operation and handling of regular expressions must be slightly different between the two tools, even though RegexBuddy has different modes that allow to mimic different environments and programming languages and I am using "Groovy/Java 1.8" which are (supposedly) the settings closest to soapUI. 

 

(Later edit: meanwhile I also wrote me a little Java test program that also compares the response with my regex using the plain vanilla java.util.regex.Pattern.matches(...)-method and it also declares that the two match perfectly, so soapUI's =~ operator must be handling things differenty that the vanilla Java regex handler!)

 

How can one make the assertion (or rather the regex evaluation within soapUI) more "verbose", so that one can find some clue, why some legal responses fail to match, so that I can correct the regex? 

 

I suspect that the handling of white-space may be different between the two, but there don't seem to be any options in soapUI to control that nor any flags to get some indication at which position of the response and/or the regex the matcher fails and then starts to backtrack. Any idea how to analyze or debug that?

  • Just for the benefit of those stumbling over this thread:

     

    The reason why my regex would not match was, that they were too complicated and caused stack-overflows in the ~ method (which unfortunately were not reported but silently ignored and interpreted as "no match").

     

    Increasing soapUI's default thread stack space fixed things. The details can be found in this thread.

1 Reply

  • mmoser18's avatar
    mmoser18
    Frequent Contributor

    Just for the benefit of those stumbling over this thread:

     

    The reason why my regex would not match was, that they were too complicated and caused stack-overflows in the ~ method (which unfortunately were not reported but silently ignored and interpreted as "no match").

     

    Increasing soapUI's default thread stack space fixed things. The details can be found in this thread.