Is someone getting the error "Test methods must be in test classes"

I am using @Istest annotation inside the class:

public class someclass{
    public static void testme(){

When I switch it to version 27 it works fine. Is this a documented expected behavior related to spring 13.Are test classes now enforced to be written in a separate test class than writing at the end of the main class?

  • From summer 13 all test methods must be in separate test class . Commented Jun 6, 2013 at 5:43
  • 3
    It's actually a good thing. The "storage usage" calculation used to lie (maybe they fixed it). It was counting the testmethods inside normal classes against your total limit of Apex code characters even though thee description claimed to be otherwise ;) So forcing to push to separate classes keeps your usage down too.
    – eyescream
    Commented Jun 6, 2013 at 6:36
  • yes u r right :)
    – swatkat
    Commented Jun 6, 2013 at 7:24

1 Answer 1


Found this in Summer'13 release notes :

Starting in Summer ‘13, test methods can be defined only in test classes (classes annotated with @isTest). You can no longer add a test method in a non-test class. This change applies to new Apex code saved using Salesforce.com API version 28.0 and later. Apex code saved using earlier API versions isn’t affected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .