Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-5899

Test methods should be discoverable

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Rename this method so that it starts with "test" or remove this unused helper.
    • Highlighting:
      Hide

      Primary: the name of the method.

      Show
      Primary: the name of the method.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Covered Languages:
      PHP
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Test Sources

      Description

      Classes subclassing unittest.TestCase are considered test cases. Methods within the class will be discovered by the test runner if their name starts with "test". If a method intended to be a test does not respect this convention, it will not be executed.

      This rule raises an issue when a method is not discoverable as a test and is never used within its test case class.

      This rule will not raise if:

      • The method is called directly from another method.
      • The method overrides an existing one in unittest.TestCase (example: a tearDown method).

      Noncompliant Code Example

      import unittest
      class MyTest(unittest.TestCase):
        def setUp(self): ... # OK (unittest.TestCase method)
        def something_test(self): ... # Noncompliant
      

      Compliant Solution

      import unittest
      class MyTest(unittest.TestCase):
        def setUp(self): ...
        def test_something(self): ...
      

        Attachments

          Issue Links

          1.
          PHP RSPEC-5934 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              guillaume.dequenne Guillaume Dequenne
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: