diff --git a/rflint/rules/testcaseRules.py b/rflint/rules/testcaseRules.py index 2ecbcbf..df56ff4 100644 --- a/rflint/rules/testcaseRules.py +++ b/rflint/rules/testcaseRules.py @@ -57,4 +57,26 @@ def apply(self, testcase): # set the line number to the line immediately after the testcase name self.report(testcase, "No testcase documentation", testcase.linenumber+1) - +class TooManyTestSteps(TestRule): + '''Workflow tests should have no more than ten steps. + + https://code.google.com/p/robotframework/wiki/HowToWriteGoodTestCases#Workflow_tests + ''' + + severity=WARNING + max_allowed = 10 + + def configure(self, max_allowed): + self.max_allowed = int(max_allowed) + + def apply(self, testcase): + if testcase.is_templated: + return + + # ignore empty test steps + steps = [step for step in testcase.steps if not (len(step) == 1 + and not step[0])] + if len(steps) > self.max_allowed: + self.report(testcase, + "Too many steps (%s) in test case" % len(steps), + testcase.linenumber) diff --git a/test_data/acceptance/rules/TooManyTestSteps.robot b/test_data/acceptance/rules/TooManyTestSteps.robot new file mode 100644 index 0000000..87b7ee0 --- /dev/null +++ b/test_data/acceptance/rules/TooManyTestSteps.robot @@ -0,0 +1,23 @@ +*** Settings *** +| Documentation +| ... | This suite has a test with too many test steps +| ... | to trigger the TooManyTestSteps rule. + +*** Test cases *** +| Test with too many steps +| | [Documentation] | example test; should trigger TooManyTestSteps rule +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation diff --git a/tests/acceptance/rules/TooManyTestSteps.robot b/tests/acceptance/rules/TooManyTestSteps.robot new file mode 100644 index 0000000..08ab41d --- /dev/null +++ b/tests/acceptance/rules/TooManyTestSteps.robot @@ -0,0 +1,74 @@ +*** Settings *** +| Documentation | Tests for the testcase rule 'TooManyTestSteps' +| Resource | tests/acceptance/SharedKeywords.robot +| # +| Test Teardown +| ... | # provide some debugging information if things go bad +| ... | Run keyword if | "${TEST STATUS}" == "FAIL" +| ... | log | ${result.stdout}\n${result.stderr} + +*** Test Cases *** +| Testcase WITHOUT too many test steps +| | [Documentation] +| | ... | Verify that a testcase without too many test steps triggers the rule. +| | +| | [Setup] | Run rf-lint with the following options: +| | ... | --no-filename +| | ... | --ignore | all +| | ... | --error | TooManyTestSteps +| | ... | ${SUITE SOURCE} | use this file as input +| | +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | No operation +| | rflint return code should be | 0 +| | rflint should report 0 errors +| | rflint should report 0 warnings + +| Testcase WITH too many test steps +| | [Documentation] +| | ... | Verify that a testcase with too many test steps triggers the rule. +| | +| | [Setup] | Run rf-lint with the following options: +| | ... | --no-filename +| | ... | --ignore | all +| | ... | --error | TooManyTestSteps +| | ... | test_data/acceptance/rules/TooManyTestSteps.robot +| | +| | rflint return code should be | 1 +| | rflint should report 1 errors +| | rflint should report 0 warnings + +| Testcase WITHOUT too many test steps after configuration +| | [Documentation] +| | ... | Verify that a testcase with too many test steps triggers the rule. +| | +| | [Setup] | Run rf-lint with the following options: +| | ... | --no-filename +| | ... | --ignore | all +| | ... | --error | TooManyTestSteps +| | ... | --configure | TooManyTestSteps:20 +| | ... | test_data/acceptance/rules/TooManyTestSteps.robot +| | +| | rflint return code should be | 0 +| | rflint should report 0 errors +| | rflint should report 0 warnings + +| Testcase WITH too many test steps after configuration +| | [Documentation] +| | ... | Verify that a testcase with too many test steps triggers the rule. +| | +| | [Setup] | Run rf-lint with the following options: +| | ... | --no-filename +| | ... | --ignore | all +| | ... | --error | TooManyTestSteps +| | ... | --configure | TooManyTestSteps:1 +| | ... | test_data/acceptance/rules/TooManyTestSteps.robot +| | +| | rflint return code should be | 1 +| | rflint should report 1 errors +| | rflint should report 0 warnings diff --git a/tests/acceptance/self-test.robot b/tests/acceptance/self-test.robot index f80e829..0465b3e 100644 --- a/tests/acceptance/self-test.robot +++ b/tests/acceptance/self-test.robot @@ -20,6 +20,7 @@ | tests/acceptance/rules/DuplicateKeywordNames.robot | 0 | tests/acceptance/rules/PeriodInSuiteName.robot | 0 | tests/acceptance/rules/PeriodInTestName.robot | 0 +| tests/acceptance/rules/TooManyTestSteps.robot | 0 | tests/acceptance/rules/LineTooLong.robot | 0 *** Keywords ***