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
Naveen Kumar Reddy YerramNaveen Kumar Reddy Yerram 

write a positive tests unit in lightning platform

@isTest
 

private class AccountWrapper_Tests {
 

  @testSetup
 

  static void loadTestData(){
 

    List<Account> accounts = (List<Account>) Test.loadData(Account.SObjectType, 'accountData');
 

    List<Opportunity> opps = new List<Opportunity>();
 

    for(Account a : accounts){
 

      opps.addAll(TestFactory.generateOppsForAccount(a.id, 1000.00, 5));
 

// Variable does not exist: TestFactory (getting this error)
    }
 

    insert opps;
 

  }
 

  @isTest static void testPositiveRoundedAveragePrice() {
 

    List<AccountWrapper> accounts = new List<AccountWrapper>();
 

    for(Account a : [SELECT ID, Name FROM ACCOUNT]){
 

      accounts.add(new AccountWrapper(a));
 

    }
 

    // sanity check asserting that we have opportunities before executing our tested method.
 

    List<Opportunity> sanityCheckListOfOpps = [SELECT ID FROM Opportunity];
 

    System.assert(sanityCheckListOfOpps.size() > 0, 'You need an opportunity to continue');
 

    Test.startTest();
 

    for(AccountWrapper a : accounts){
 

        
 

        System.assertEquals(a.getRoundedAvgPriceOfOpps(), 1000.00, 'Expected to get 1000.00');
 

        System.assert(!a.isHighPriority());
 

    }
 

    Test.stopTest();
 

  }
 

}
Abdul KhatriAbdul Khatri
Hi Naveen,

How is your TestFactory looks like, would you mind to share?

Is generateOppsForAccount a static method in the class?
Abdul KhatriAbdul Khatri
Hi Naveen

Your issue fixed?