function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TristanLSTristanLS 

All tests using System.runAs(<user>) fail since Spring '11 upgrade

Every single tests in my managed package that uses System.runAs(<user>) fails after Spring '11 upgrade.

 

Here are some examples of things that used to pass but now fail:

 

static Profile p = [select id from profile where name ='Standard User'];

static User u1 = new User(

    alias = 'testuser',

    email = 'testuser@test.com',

    emailencodingkey='UTF-8',

    lastname = 'User',

    languagelocalekey='en_US',

    localesidkey='en_US',

    profileid = p.id,

    timezonesidkey='America/Chicago',

    username='testuser@testmagic.com'

  );

static User u2 = new User(...);

 

static testMethod void doAnythingAtAllAsSomeoneElse() {

  Setting__c s;

  System.runAs(u2) {

    s = new Setting__c(Name = 'skipIntro', Value__c = 'true');

    insert s;

  }

  System.runAs(u1) {

    settings = new MySettings();

  }

 

  System.assert(settings.settingsMap.get('skipIntro') == null);

 

  delete s;

}

 

The test above used to work fine. In this particular instance, when it gets to "insert s;", it wll fail with "System.TypeException: DML operation INSERT not allowed". In a different test, it will tell me that static objects that were created aren't there and can't be referenced.

 

Are there some sort of permissions / testing / System.runAs changes in Spring '11 I'm not aware of?

 

Thanks,

 

Tristan