Forum Discussion

cinne's avatar
cinne
Occasional Contributor
8 years ago

How to call/run an assertion in a Groovy Script?

For maintenance purposes I'm trying to centralize test steps in one single test case as much as possible. Usually this test case has an XQuery Match Assertion which checks some nodes for a given id. I'd like though implementing a conditional assertion script which would allow me calling specific assertions according to a given control property, so that I do not need 2 different test cases due to assertion points.

 

For instance that's more or less the structure I'd like to implement:

--------------------

- MainTestCase: JDBC Connection executing a simple Select

--------------------

   - NotContainsAssertion (disabled)

        check if the sql does not return a given ID

   - XQueryAssertion (disabled)

        check the sql results for a given ID

  - Script Assertion:

        if control=0, calls NotContainsAssertion

        if control=1, calls XQueryAssertion

 

--------------------

- PositiveTestCase: 

--------------------

  - control=1

  - Run_MainTestCase

       it will run the XQueryAssertion

 

--------------------

- NegativeTestCase: 

--------------------

  - control=0

  - Run_MainTestCase

       it will run the NotContainsAssertion

 

Is it somehow possible calling/running an assertion from a script? Any suggestions?

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    It would be more simple if just do the in Script Assertion itself.
    • cinne's avatar
      cinne
      Occasional Contributor

      I though about this possibility in first place but as the test case has already some XQuery assertions I decided giving it a try and asking if it would be possible creating a control script only. Thanks anyway, Rao.

       

      BR,

      Cinne

      • nmrao's avatar
        nmrao
        Champion Level 3
        I didn't anyway mean to say not possible. Of course, it is very much possible.

        I told that way because you are anyway using script assertion where you got fine control to do so.
  • I'm not sure if this is what you're referring to, but do you mean a Groovy assertion?

     

    • assert <reason>, case

     

    For example:

     

    • assert "A does not equal B", a == b
    • cinne's avatar
      cinne
      Occasional Contributor

       

      That was not actually what I meant. I'd like to call some SoapUI-Assertions that were already implemented on a test case, for instance Xpath, XQuery, Contains etc, so that I would not need to re-write these assertions in a groovy script. I'd like calling the assertion "objects" instead.

       

      I actually did what davy suggested but I still wonder how I could get it done :)