You need to sign in to do that
Don't have an account?
Naveen 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();
}
}
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();
}
}
How is your TestFactory looks like, would you mind to share?
Is generateOppsForAccount a static method in the class?
Your issue fixed?