---
title: Test Methods Must Be In Test Classes
description: "**Impact area** Performance **Severity** Medium **Affected element** Apex Class ## Rule ID SF-OVERRIDE-BOTH ## Impact Test methods marked as a testMethod or annotated with @IsTest, but not residing in a test class should be moved to a proper class or…"
url: "https://community-staging.qualityclouds.com/qcdocs/qcr/rules/test-methods-must-be-in-test-classes/"
updated: "2025-03-21"
category: PMD Rules
---

# Test Methods Must Be In Test Classes

**Impact area**

Performance

**Severity**

Medium

**Affected element**

Apex Class

## Rule ID

SF-OVERRIDE-BOTH

## Impact

Test methods marked as a testMethod or annotated with @IsTest, but not residing in a test class should be moved to a proper class or have the @IsTest annotation added to the class. Support for tests inside functional classes was removed in Spring-13 (API Version 27.0), making classes that violate this rule fail compile-time. 

Remediation

Create an apex class with @isTest annotation and move the method to the class.

### Time to fix

30 min

## References

This rule is linked to [TestMethodsMustBeInTestClasses](https://pmd.github.io/pmd/pmd_rules_apex_errorprone.html#testmethodsmustbeintestclasses)
