+ Start a Discussion
Ilene JonesIlene Jones 

Unknown annotation: testSetup

I just finished writing and testing my apex and visual force page in Spring '15.  I decided to use the @testSetup method since I have a few different ways that I wanted to test this code.  I used the standard syntax, and all was well in Spring '15 - 85% code coverage, not perfect but I can come back to refine later for those extra few percentage points - Time to DEPLOY to production!  Not so much.  

Validation fails in production (Winter '15) with the error: Unknown annotation: testSetup ... 

I tried switching the API version to a lower version (droped it to 30) and the annotation error persists.

I followed the instructions here to no avail: 
https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_annotation_testsetup.htm|StartTopic=Content%2Fapex_classes_annotation_testsetup.htm|SkinName=webhelp

My test class is structured properly and has no errors in my sandbox.  Is this just a bug in the Spring '15 beta?

@isTest
public class ClubMembershipControllerTest {

    //
    // First, set up our dataset that all other test methods will use
    // 
    @testSetup static void setup() {
        // my inserts are here

    }
    //
    // This is a negative test to make sure that the student application cannot be duplicated.
    // This test is specifically to test the trigger code.
    //     
    public static testMethod void studentClubApplicationTest() {
        // first test case that uses the above inserts.
    }    
}
 


 

Best Answer chosen by Ilene Jones
James LoghryJames Loghry
Right, what the documentation says is that you can adjust the API version of your class, and the testSetup annotation will work for any API versions of 24.0 or greater.  However, what it doesn't say is that the @testSetup annotation simply does not exist on your production org yet.  It has not been rolled out to most naXX instances (including the instance that my developer org runs on).  Hence, why it throws the "no annotation found" error when you try to deploy your test code.

What you're going to have to do is either modify your test code to construct the data for each of your methods, or simply wait until the Spring release is rolled out to your instance.

All Answers

James LoghryJames Loghry
Spring '15 has not rolled out to all instances yet.  You can see which instances are still due to receive the upgrade here: http://trust.salesforce.com/trust/maintenance/.  The last scheduled window is Feb. 14th, so it's coming soon.  However, you'll have to wait until then to use the @testSetup annotation on the org, most likely.
Ilene JonesIlene Jones
The documentation that I linked to above says:  
Because data isolation for tests is available for API versions 24.0 and later, test setup methods are also available for those versions only.

This leads me to believe that it should be available in v30+ as well since there is no notice of deprication.
James LoghryJames Loghry
Right, what the documentation says is that you can adjust the API version of your class, and the testSetup annotation will work for any API versions of 24.0 or greater.  However, what it doesn't say is that the @testSetup annotation simply does not exist on your production org yet.  It has not been rolled out to most naXX instances (including the instance that my developer org runs on).  Hence, why it throws the "no annotation found" error when you try to deploy your test code.

What you're going to have to do is either modify your test code to construct the data for each of your methods, or simply wait until the Spring release is rolled out to your instance.
This was selected as the best answer
Ilene JonesIlene Jones

Apparently I missed this in the Spring '15 release documentation.  It would be nice if the standard documentation actually mentioned when it would be released if it's part of a pre-release/Beta, as I thought it was available.

http://releasenotes.docs.salesforce.com/en/spring15/release-notes/rn_apex_test_setup_methods.htm