I had a working Queueable class doing callouts. My unit tests were passing but I had to change my class slightly. I encountered the callout exception and I started tracing down the culprit.
The problem appears to be in the test set up. For some reason creating an opportunity object breaks the test. (The opportunity is not used by the code. I managed to break the older working tests just by adding this one insert).
static void test_batch(){
TriggerStopper.stopForTest = true;
Account oAccount = new Account(Name ='Name');
insert oAccount;
//insert new Opportunity(Name='this breaks the test', AccountId = oAccount.Id);
Test.setMock(WebServiceMock.class , new myMocks.SuccessMockImpl());
Test.startTest();
System.enqueueJob(new myBatch());
Test.stopTest();
}
Funny enough the test also breaks when I move the creation of objects into @testSetup method.
I don't understand what the reason could be.
The batch doesn't do any DML before the callout and the test works if I comment out the insertion of opportunity.
It's not the opportunity trigger doing suspicious inserts as it's stopped for the purpose of test set up. I'm really baffled.
How can I fix the test?