Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rule for too many steps in test case #9

Merged
merged 8 commits into from
Jan 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion rflint/rules/testcaseRules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 23 additions & 0 deletions test_data/acceptance/rules/TooManyTestSteps.robot
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions tests/acceptance/rules/TooManyTestSteps.robot
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/acceptance/self-test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***
Expand Down