You need to sign in to do that
Don't have an account?
Ravindra Kashyap 2
@istest(SeeAllData=true) and @testsetup not working
Hello everyone,
When I am trying to test my class using test setup method then IDE is giving an error. There is any way to avoid this and use both methods during test??
@IsTest
global class AddPrimaryContactTest
{
@TestSetup
static void setup()
{
List<Account> accountList = new List<Account>();
for(Integer i = 1; i <= 50; i++)
{
accountList.add(new Account(name = 'Test Account'+ i, BillingState = 'CA'));
}
for(Integer i = 50; i <= 100; i++)
{
accountList.add(new Account(name = 'Test Account'+ i, BillingState = 'NY'));
}
insert accountList;
}
@IsTest(SeeAllData=true)
global static Void test()
{
Contact con = new Contact(Firstname ='conFirst',lastname='conLast');
AddPrimaryContact obj = new AddPrimaryContact(con,'CG');
Test.startTest();
System.enqueueJob(obj);
Test.stopTest();
List<Account> count = [select id,(select id from contacts) from Account where BillingState = 'CA'];
System.debug('countcontact = ' + count.size() );
System.assertEquals(50, count.size());
}
}
thanks in Advance :)
When I am trying to test my class using test setup method then IDE is giving an error. There is any way to avoid this and use both methods during test??
@IsTest
global class AddPrimaryContactTest
{
@TestSetup
static void setup()
{
List<Account> accountList = new List<Account>();
for(Integer i = 1; i <= 50; i++)
{
accountList.add(new Account(name = 'Test Account'+ i, BillingState = 'CA'));
}
for(Integer i = 50; i <= 100; i++)
{
accountList.add(new Account(name = 'Test Account'+ i, BillingState = 'NY'));
}
insert accountList;
}
@IsTest(SeeAllData=true)
global static Void test()
{
Contact con = new Contact(Firstname ='conFirst',lastname='conLast');
AddPrimaryContact obj = new AddPrimaryContact(con,'CG');
Test.startTest();
System.enqueueJob(obj);
Test.stopTest();
List<Account> count = [select id,(select id from contacts) from Account where BillingState = 'CA'];
System.debug('countcontact = ' + count.size() );
System.assertEquals(50, count.size());
}
}
thanks in Advance :)
Thanks Pradeep for link :)
All Answers
Please refer.......https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_testsetup_using.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_testsetup_using.htm" target="_blank)
Thanks Pradeep for link :)