SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Apex

Apex static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your APEX code

  • All rules 97
  • Vulnerability2
  • Bug26
  • Security Hotspot3
  • Code Smell66
Filtered: 5 rules found
testing
    Impact
      Clean code attribute
        1. Arguments to "assertEquals" and "assertNotEquals" should be in the correct order

           Code Smell
        2. SOSL queries in test methods should use "Test.setFixedSearchResults"

           Code Smell
        3. Test classes and methods should not use "seeAllData=true"

           Code Smell
        4. Private members made public for testing should use "@TestVisible" annotation

           Code Smell
        5. Test methods should include meaningful assertions

           Code Smell

        Arguments to "assertEquals" and "assertNotEquals" should be in the correct order

        intentionality - clear
        maintainability
        Code Smell
        • testing
        • confusing

        This rule raises an issue when the arguments to System.assertEquals or System.assertNotEquals appear to be in the wrong order, with the actual value likely passed as the first argument instead of the expected value.

        Why is this an issue?

        How can I fix it?

        More Info

        The System.assertEquals and System.assertNotEquals methods follow the convention of assertEquals(expected, actual), where the first argument is the expected value and the second is the actual value being tested.

        When these arguments are reversed, the test logic remains correct - it will still pass or fail appropriately. However, the error messages become confusing and misleading when the test fails.

        For example, if you write System.assertEquals(myList.size(), 0) and the list actually contains 4 elements, the failure message will show: Expected: 4, Actual: 0

        This is backwards from what you intended to test. You expected 0 elements but got 4, so the message should read Expected: 0, Actual: 4.

        This confusion makes debugging more difficult, especially when:

        • Multiple developers work on the same codebase
        • Tests fail in CI/CD pipelines where quick understanding is crucial
        • Complex test scenarios where clear error messages are essential for troubleshooting

        Following the correct argument order makes your tests more maintainable and debugging more straightforward.

        What is the potential impact?

        When test assertions fail, the error messages will display confusing information that makes debugging more difficult and time-consuming. This can slow down development and increase the likelihood of misunderstanding test failures.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use