How to unit test works in salesforce?

后端 未结 3 1231
半阙折子戏
半阙折子戏 2021-01-21 08:25

I\'ve done writing code on salesforce and in order to release the unit tests have to cover at least 75%.

What I am facing is that the classOne

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 08:26

    I created an Apex class called TestHelper for all my mock objects. I use constants (static final) for values that I might need elsewhere and public static fields for objects. Works great and since no methods are used, no test coverage is needed.

    public without sharing class TestHelper {
    public static final string testPRODUCTNAME = 'test Product Name';
    public static final string testCOMPANYID = '2508'; 
    
    public static Account testAccount {
        get{
            Account tAccount = new Account(
                Name = 'Test Account',
                BillingStreet = '123 Main St',
                BillingCity = 'Dallas',
                BillingState = 'TX',
                BillingPostalCode = '75234',
                Website = 'http://www.google.com',
                Phone = '222 345 4567',                
                Subscription_Start_Date__c = system.today(),
                Subscription_End_Date__c = system.today().addDays(30),
                Number_Of_Seats__c = 1,
                companyId__c = testCOMPANYID,
                ZProduct_Name__c = testPRODUCTNAME);      
            insert tAccount;
            return tAccount; 
        }
    }
    

    }

提交回复
热议问题