@isTest
public class CaseUtilityTest {
@isTest static void TestCreateCase()
{
Test.startTest();
CaseUtility.CreateCase(100,false); // 1
Test.stopTest();
Test.startTest();
CaseUtility.CreateCase(100,true); //2
Test.stopTest();
}
@isTest static void TestDeleteAll()
{
Test.startTest();
CaseUtility.DeleteAll();
List<Case> c_list = [SELECT ID FROM Case];
System.assertEquals(c_list.size(), 0);
Test.stopTest();
}
}
Class
public class CaseUtility {
@future
public static void CreateCase(Integer num,Boolean sa_yes)
{
List<Case> case_list = new List<Case>();
for(Integer cnt = 0; cnt < num; cnt++)
{
if(sa_yes)
{
case_list.add(new Case(AccountId = '00128000002iZHI',SpendAccount__c = 'a0028000005YEoO',Reason = 'SAMPLE CASE # '+cnt));
}
else
{
case_list.add(new Case(AccountId = '00128000002iZHI',Reason = 'SAMPLE CASE # '+cnt));
}
}
insert case_list;
}
@future
public static void DeleteAll()
{
delete ([SELECT ID FROM Case]);
}
}
When I try to do a test run I am getting the following error in this test method (TestCreateCase()), I believe it is because I am calling .start/.stoptest two times within the same method.
System.FinalException: Testing already started (System Code) Class.CaseUtilityTest.TestCreateCase: line 10, column 1
But I am not able to understand the reasoning behind that error..
Can someone let me know why I am getting the error ?