There are 2 methods will callout and insert.I wrote 2 batches to invoke my method. I use the one invoke the other one to avoid System.CalloutException,and it's useful when i run them.
global void finish(Database.BatchableContext BC) {
Database.executeBatch(new TrelloChangeTaskBatch());
}
But when i create MockHttpCallout class and use Test.startTest() and stopTest() in my test class to run the batches.
Test.startTest();
Test.setMock(HttpCalloutMock.class, new MockTrelloHttpResponseGenerator());
Database.executeBatch(new TrelloBatch());
Test.stopTest();
it's still happened.
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out in test class
I tried to delete startTest() and stopTest() but it's invalid.More than that i can't use @feature. Somebody told my isRunningTest() maybe useful, but i don't know how to use it in my case because there are no example in document.
Anybody know how to solve this problem in unit test? Thanks a lot!