Forum Discussion

rajs2020's avatar
rajs2020
Frequent Contributor
4 years ago
Solved

Fluent or English like assertions in Groovy?

In groovy scripts, for assertions, I see that only the assert statement is used. Instead of that, I would like to use English like assertions similar to the ones in these Java testing libraries - TestNg, Junit and Hamcrest etc.

Hamcrest asserts:

assertThat(list, both(hasSize(1)).and(contains(42)));

Groovy asserts:
assert list.size == 1
assert list.contains(42)

This is just a small example, so it might seem like hamcrest is not very different or useful than the simple assert. To see the benefits of hamcrest, see more detailed examples.

  • Yes it is very much possible, nothing is stopping you to do so.

    All you need is to add the respective depencies into READYAPI_HOME/bin/ext directory and restart the tool.

     

    Here is the same example you cited:

     

     

9 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    Yes it is very much possible, nothing is stopping you to do so.

    All you need is to add the respective depencies into READYAPI_HOME/bin/ext directory and restart the tool.

     

    Here is the same example you cited:

     

     

    • rajs2020's avatar
      rajs2020
      Frequent Contributor

      nmrao- Thank you. I will try that.

      If we add dependencies like this in Maven, then sometimes there can be conflicts in dependencies. So, I wonder if adding new dependencies to ready api can also potentially cause conflicts. Is there a way to check for such conflicts? I don't want to find out later that I broke the project.

      • nmrao's avatar
        nmrao
        Champion Level 3

        Need to have more specific details for the followup question.
        Have you tried and landed into such situation?
        Note that when the library is added it won't broke your project if you place any libraries, just remove them from where they are placed.
        It is easy to identify the what dependency and its version by just looking at READYAPI_HOME/lib directory. General thumb rule is to check it before placing it under bin/ext directory.

  • rajs2020 : ReadyAPI support groovy script for coding so we can use assert command for the assertion purpose, not sure on how you can use java like assertions.

     

    sonya_m : can you please provide any information on this, if we can use java like assertions or not.