You need to sign in to do that
Don't have an account?
revathy
Test class for apex approval process?getting error
System.AssertException: Assertion Failed: Instance StatusPending: Expected: Approved, Actual: Pending
My Test Class
========
@isTest(SeeAllData=true)
public class GE_LGT_EM_ApproveReject_test{
static testMethod void myUnitTest() {
// Insert an account
Case Caseobj=new Case(GE_LGT_EM_Salesorg__c='2BE1',Subject='test sample data');
insert Caseobj;
GE_LGT_EM_InvoiceLineItem__c newrec=new GE_LGT_EM_InvoiceLineItem__c(Name='testinvoicedata',CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_NO__c='5000');
insert newrec;
GE_LGT_EM_ComplaintLineItem__c acc = new GE_LGT_EM_ComplaintLineItem__c(GE_LGT_EM_Category__c='118-Product Mispick-Return',GE_LGT_EM_Comments__c='sample data',GE_LGT_EM_CaseNumber__c=Caseobj.id,CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_Number__c='500');
insert acc ;
Test.setMock(WebServiceMock.class, new GE_LGT_EM_171WebServiceMockImpl_test());
// Create an approval request for the cli
Approval.ProcessSubmitRequest req1 =new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(acc.id);
// Submit the approval request for the cli
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
// Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setAction('Approve');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals('Approved', result2.getInstanceStatus(), //here getting error
'Instance Status'+result2.getInstanceStatus());
}
}
}
please help me on this
My Test Class
========
@isTest(SeeAllData=true)
public class GE_LGT_EM_ApproveReject_test{
static testMethod void myUnitTest() {
// Insert an account
Case Caseobj=new Case(GE_LGT_EM_Salesorg__c='2BE1',Subject='test sample data');
insert Caseobj;
GE_LGT_EM_InvoiceLineItem__c newrec=new GE_LGT_EM_InvoiceLineItem__c(Name='testinvoicedata',CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_NO__c='5000');
insert newrec;
GE_LGT_EM_ComplaintLineItem__c acc = new GE_LGT_EM_ComplaintLineItem__c(GE_LGT_EM_Category__c='118-Product Mispick-Return',GE_LGT_EM_Comments__c='sample data',GE_LGT_EM_CaseNumber__c=Caseobj.id,CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_Number__c='500');
insert acc ;
Test.setMock(WebServiceMock.class, new GE_LGT_EM_171WebServiceMockImpl_test());
// Create an approval request for the cli
Approval.ProcessSubmitRequest req1 =new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(acc.id);
// Submit the approval request for the cli
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
// Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setAction('Approve');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals('Approved', result2.getInstanceStatus(), //here getting error
'Instance Status'+result2.getInstanceStatus());
}
}
}
please help me on this
after i added Test.startTest() and Test.stopTest() still getting same error,please help me more
@isTest(SeeAllData=true)
public class GE_LGT_EM_ApproveReject_test{
static testMethod void myUnitTest() {
Test.startTest();
Case Caseobj=new Case(GE_LGT_EM_Salesorg__c='2BE1',Subject='test sample data');
insert Caseobj;
GE_LGT_EM_InvoiceLineItem__c newrec=new GE_LGT_EM_InvoiceLineItem__c(Name='testinvoicedata',CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_NO__c='5000');
insert newrec;
GE_LGT_EM_ComplaintLineItem__c acc = new GE_LGT_EM_ComplaintLineItem__c(GE_LGT_EM_Category__c='118-Product Mispick-Return',GE_LGT_EM_Comments__c='sample data',GE_LGT_EM_CaseNumber__c=Caseobj.id,CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_Number__c='500');
insert acc ;
Test.setMock(WebServiceMock.class, new GE_LGT_EM_171WebServiceMockImpl_test());
// Create an approval request for the cli
Approval.ProcessSubmitRequest req1 =new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(acc.id);
// Submit the approval request for the cli
Approval.ProcessResult result = Approval.process(req1);
Test.stopTest();
// Verify the result
System.assert(result.isSuccess());
System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
// Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setAction('Approve');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
system.debug('--------->'+result2);
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals('Approved', result2.getInstanceStatus(),
'Instance Status'+result2.getInstanceStatus());
}
}