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: 2 rules found
test
    Impact
      Clean code attribute
        1. Test classes should have only one @testSetup method

           Bug
        2. Test classes should be annotated with "@isTest"

           Code Smell

        Test classes should have only one @testSetup method

        intentionality - logical
        reliability
        maintainability
        Bug
        • apex
        • test

        This is an issue when a test class contains multiple methods annotated with @testSetup.

        Why is this an issue?

        How can I fix it?

        More Info

        In Apex, test classes can only contain one @testSetup method. The @testSetup annotation is used to create test data that will be available to all test methods in the class, improving test performance by avoiding duplicate data creation.

        When you define multiple @testSetup methods in the same test class, the Apex compiler will reject the code and throw a compilation error. This happens because the Salesforce platform expects exactly one setup method per test class to maintain predictable test execution order and data consistency.

        The @testSetup method runs once before all test methods in the class, creating a clean, consistent data state. Having multiple setup methods would create ambiguity about execution order and could lead to unpredictable test behavior.

        What is the potential impact?

        Multiple @testSetup methods will cause compilation errors, preventing the test class from being deployed or executed. This blocks development progress and can prevent deployments to production environments.

          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