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

Assertions should not be used in production code

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Remove this assertion from production code.
    • Highlighting:
      Hide

      Assertion method name.

      Show
      Assertion method name.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Java
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources

      Description

      Assertions are intended to be used in test code, but not in production code. It is confusing, and might lead to ClassNotFoundException when the build tools only provide the required dependency in test scope.
      In addition, assertions will throw a sub-class of Error: AssertionError, which should be avoided in production code.

      This rule raises an issue when any assertion intended to be used in test is used in production code.

      Supported frameworks:

      • JUnit
      • FestAssert
      • AssertJ

      Note: this does not apply for assert from Java itself or if the source code package name is related to tests (contains: test or assert or junit).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: