What is the best way of doing assertions in Robot Framework?

Farkas István :

I'm using Robot Framework with Java. My question is: what is the best way of doing assertions in Robot Framework? Should I import JUnit (or a similar library) and use if for assertions in my own keyword?

Is there a keyword library for assertions? I mean a library that contains keywords something like this:

Assert True &{value_to_check}
Assert List Contains &{list_of_elements} &{element_to_find} # using java equals method

Thank you!

Todor Minakov :

For the majority of the use cases you don't need an external library (especially a java one), but check what is baked in the BuiltIn and the Collections libraries.
You have to explicitly import the latter, while BuiltIn is always available.

All keywords that have "should" in their name are asserts - Should Be True, Should Contain (that's for membership - works on lists, dicts, strings - any container), List Should Contain Sub List, and some even do type casting on the arguments - Should Be Equal As Numbers.

This pattern (of "should" being asserts) is followed in other (external) libraries - in the SeleniumLibrary, for example.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=164839&siteId=1