robotframework-robocop
robotframework-robocop copied to clipboard
[Rule] Suggest using robot:continue-on-failure
It could be good candidate for user/custom rule.
I have often seen code like this:
Validate Stuff
Run Keyword And Continue On Failure
... Length Should Be ${variable} 1
Run Keyword And Continue On Failure
... Should Be Equal ${expected['key1']} ${actual['key11']}
Run Keyword And Continue On Failure
... Should Be Equal ${expected['key2']} ${actual['key12']}
Run Keyword And Continue On Failure
... Should Be Equal ${expected['key3']} ${actual['key14']}
Run Keyword And Continue On Failure
... Should Be Equal ${expected['key4']} ${actual['key3']}
Sometimes it can be refactored to other, more readable form but sometimes it's necessity. Robot Framework 5/6 introduced new tags that can help refactor this code: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#enabling-continue-on-failure-using-tags
With that it could become:
Validate Stuff
[Tags] robot:continue-on-failure
Length Should Be ${variable} 1
Should Be Equal ${expected['key1']} ${actual['key11']}
Should Be Equal ${expected['key2']} ${actual['key12']}
Should Be Equal ${expected['key3']} ${actual['key14']}
Should Be Equal ${expected['key4']} ${actual['key3']}
The rule can check if more than x Run Keyword And Continue On Failure is used in test/keyword and propose to use this tag (or more than x%)
There is also candidate for opposite rule: if there is tag robot:continue-on-failure
or robot:recursive-continue-on-failure
but keyword/test contains Run Keyword And Continue On Failure
(now unnecessary with those tags). It will not be perfect - since recursive also applies to called keywords - but it's fine since it'll be custom rule.