Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robot Framework Succeed on Exception

I am testing a software component and want that software to throw an Exception in certain situations. I want to reproduce these situations by using the robot framework.

  • The testcase shall succeed if I catch a specific Exception (which I am expecting, because I am deliberately creating an error-state in my component under test)
  • The testcase shall fail if I do not receive the specific Exception (i.e. my component under test did not fail(throw an exception) in an error situation)

What I am looking for is something like this:

prepareErrorInTestEnvironment
try 
    executeComponentWhichThrowsException
except
    pass
fail
like image 948
Martin Perzl Avatar asked Mar 18 '26 12:03

Martin Perzl


1 Answers

Treatment of "expected exception" are a bit specific in Robot Framework as usually exception will fail the keyword and hence the test. The keyword you are looking for is Run Keyword and Expect Error.

Your test would look like

*** Test Cases ***
my test
    prepareErrorInTestEnvironment
    Run Keyword and Expect Error  TheExceptionYouExpect  executeComponentWhichThrowsException

This will success if you get the proper exception, and fail otherwise

like image 76
Laurent Bristiel Avatar answered Mar 21 '26 07:03

Laurent Bristiel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!