You need to sign in to do that
Don't have an account?
Naveen Kumar Reddy Yerram
Variable does not exist: TestFactory at line 8 column 19
@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));
// anyone tell me where to see for that variable wether it is there are not?
}
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');
}
Test.stopTest();
}
@isTest static void testHighPriority() {
List<AccountWrapper> accounts = new List<AccountWrapper>();
for(Account a : [SELECT ID, Name FROM ACCOUNT]){
accounts.add(new AccountWrapper(a));}
List<Opportunity> opps = new List<Opportunity>();
opps = [SELECT Id,Amount FROM Opportunity];
for(Opportunity opp :opps ) {
opp.amount =2000000;
}
update opps;
Test.startTest();
for(AccountWrapper a : accounts){
System.assertEquals(a.isHighPriority(), true, 'Priority expected to be high');
System.debug('get rounded price of opps for accounts b:'+ a.getRoundedAvgPriceOfOpps());
}
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));
// anyone tell me where to see for that variable wether it is there are not?
}
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');
}
Test.stopTest();
}
@isTest static void testHighPriority() {
List<AccountWrapper> accounts = new List<AccountWrapper>();
for(Account a : [SELECT ID, Name FROM ACCOUNT]){
accounts.add(new AccountWrapper(a));}
List<Opportunity> opps = new List<Opportunity>();
opps = [SELECT Id,Amount FROM Opportunity];
for(Opportunity opp :opps ) {
opp.amount =2000000;
}
update opps;
Test.startTest();
for(AccountWrapper a : accounts){
System.assertEquals(a.isHighPriority(), true, 'Priority expected to be high');
System.debug('get rounded price of opps for accounts b:'+ a.getRoundedAvgPriceOfOpps());
}
Test.stopTest();
}
}
It seems like the Class TestFactory is not available in one of your environment. Can you try ctrl+shift+O and in the popup type *TestFactory*. If you're able to get the result with the name TestFactory.apxc then open the class and then look for the method generateOppsForAccount and see what that method is returning.
If you're unable to find the class then you need to search same class in your other environment including Production. If it's not then you need to create a new class with the method from which you can generate your test Opportunity record.
You can also try to search in files by Ctrl+shift+h and in pop up type *TestFactory* and see if you can find anything related to TestFactory.
*TestSuiteMembership.obj* => This is basically Object defination and not the class.
Thanks,
Ashish Singh.
All Answers
Please opne TestFactory class and share the line 8 code with me , or you can share TestFactory.generateOppsForAccount code for me for investigation
REgards
Mukesh
Hi Naveen,
Please try with "TestDataFactory" instead of "TestFactory".
If it resolve, please mark it as best answer.
regards,
Priya Ranjan
It seems like the Class TestFactory is not available in one of your environment. Can you try ctrl+shift+O and in the popup type *TestFactory*. If you're able to get the result with the name TestFactory.apxc then open the class and then look for the method generateOppsForAccount and see what that method is returning.
If you're unable to find the class then you need to search same class in your other environment including Production. If it's not then you need to create a new class with the method from which you can generate your test Opportunity record.
You can also try to search in files by Ctrl+shift+h and in pop up type *TestFactory* and see if you can find anything related to TestFactory.
*TestSuiteMembership.obj* => This is basically Object defination and not the class.
Thanks,
Ashish Singh.
TestFactory is a custom class which was created into this step -
https://trailhead.salesforce.com/content/learn/modules/unit-testing-on-the-lightning-platform/generate-data-for-tests
Or just follow this Solution -
1. Create a Apex class TestFactory
2. Copy this code
3. Select this as best answer.