• LiamCo
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies

Hi,

 

We're using the the Force.com migration tool to deploy code into our integration and test instances using ant and as part of the deployment we run the unit tests which have just started failing since we moved to Winter 13.

 

I've narrowed the problem down to calls to the getInstance method on custom settings objects. The problem only manifests itself when the tests are run from the build.xml file, if I run the code directly from the site it works fine, even though I am logged on as the same user in each case.

 

If I call

 

Connect_Category_Scale__c.getInstance('100');

 

it returns null but if I call

 

Map<string, Connect_Category_Scale__c> allCCS = Connect_Category_Scale__c.getAll();

allCCS.get('100');

 

the expected value is returned.

 

I have installed the latest version of the migration tool from our site.

 

Does anyone have any ideas as to why this is happening ?

 

Thanks,

 

Liam

 

  • September 24, 2012
  • Like
  • 0

Hi,

 

I'm trying to use ant to deploy code into a sandbox environment and run the tests as part of the build. However, if I set runAllTests="true" then it will run all the managed package tests as well, many of which fail which breaks the build.

 

Is there a way to only run our unit tests ?

 

Thanks,

 

Liam

Hi,

 

is it possible to use the runAs method to test the object permissions for a Profile in your test code ?

 

It doesn't seem to work for me.

 

thanks,

 

Liam

 

  • March 15, 2011
  • Like
  • 0

Winter 13 anomaly 

 

I have a test class Foo that among other things:

 

* inserts a ContentVersion

* inserts a ContentWorkspaceDoc

* updates the ContentVersion with custom field values and tags

 

If I login to the Winter13 sandbox using credentials for system administrator X, select class Foo and Run Tests - the tests pass fine

 

If I use Ecliipse IDE Version 24.0.0.201202291629 also logged in as user X and do Apex Test Runner on the very same class Foo, I get the error:

System.DmlException: Update failed. First exception on row 0 with id 068V00000008ILuIAM; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

 

where the ID is the ID of the ContentVersion record and the DML is on the Update of the ContentVersion record

 

These tests all ran fine in Eclipse prior to the sandbox being upgraded to Winter 13

 

Here's what I don't get:

Doesn't Eclipse IDE simply instruct the sandbox cloud to execute the test class Foo, all execution occurs in the sandbox cloud, and the results/log are merely passed back to Eclipse?

 

Given that the Ecliipse project uses the same credentials as those I use to UI login to the Force.com platform, the Eclipse test execution should execute the same as running the test via a Force.com Run Tests button click. True?

 

What could be different here? Does the Winter 13 sandbox code somehow execute the test class submitted by Eclipse with different context than when I execute it from the Force.com UI?  I've never seen this before and I've been running this APEX class in Eclipse successfully since V19.0

 

In preparation for the Force.com AppExchange Security Review (see e.g. Requirements Checklist) I have been trying to write unit tests for my application's CRUD security and FLS logic.

 

The two tests below demonstrate the problem that I have got stuck on. System.runAs can have an impact on the describe call result as isUpdateable is false in the first test class and true in the second. But the first obtained describe data remains cached both within a test method and across the whole test class.

 

I'm looking for suggestions on how to write CRUD security and FLS tests given this unexpected behavior.

 

Thanks, Keith

 

@isTest
private class DescribeFalseTest {

    @isTest
    static void testOne() {
    
        // Observed bizarre behavior: if first call is false rest will be false
        System.runAs(readOnlyUser()) {
            System.assertEquals(false, Account.SObjectType.getDescribe().isUpdateable());
        }

        System.assertEquals(false, Account.SObjectType.getDescribe().isUpdateable());
    }

    @isTest
    static void testTwo() {

        System.assertEquals(false, Account.SObjectType.getDescribe().isUpdateable());
        
        System.runAs(readOnlyUser()) {
            System.assertEquals(false, Account.SObjectType.getDescribe().isUpdateable());
        }
    }
    
    private static User readOnlyUser() {

        Profile p = [select Id, Name from Profile where Name = 'Read Only'];
        User u = new User(
            UserName = 'test-user@test-company.com',
            FirstName = 'Test-First-Name',
            LastName = 'Test-Last-Name',
            Alias = 'test',
            Email = 'test-user@test-company.com',
            EmailEncodingKey = 'UTF-8',
            LanguageLocaleKey = 'en_US',
            LocalesIdKey = 'en_US',
            TimezonesIdKey = 'America/Los_Angeles',
            ProfileId = p.Id
            );
        insert u;
        return u;
    }
}

 

@isTest
private class DescribeTrueTest {

    @isTest
    static void testOne() {
    
        // Observed bizarre behavior: if first call is true rest will be true
        System.assertEquals(true, Account.SObjectType.getDescribe().isUpdateable());
        
        System.runAs(readOnlyUser()) {
            System.assertEquals(true, Account.SObjectType.getDescribe().isUpdateable());
        }
    }

    @isTest
    static void testTwo() {

        System.runAs(readOnlyUser()) {
            System.assertEquals(true, Account.SObjectType.getDescribe().isUpdateable());
        }

        System.assertEquals(true, Account.SObjectType.getDescribe().isUpdateable());
    }
    
    private static User readOnlyUser() {

        Profile p = [select Id, Name from Profile where Name = 'Read Only'];
        User u = new User(
            UserName = 'test-user@test-company.com',
            FirstName = 'Test-First-Name',
            LastName = 'Test-Last-Name',
            Alias = 'test',
            Email = 'test-user@test-company.com',
            EmailEncodingKey = 'UTF-8',
            LanguageLocaleKey = 'en_US',
            LocalesIdKey = 'en_US',
            TimezonesIdKey = 'America/Los_Angeles',
            ProfileId = p.Id
            );
        insert u;
        return u;
    }
}