I have two different scheduled classes that I am trying to schedule from a single test class. A simplification is the first class creates a set of records, and then the second class does something else with those records.
I can write a test class for either of them, but since they are so closely linked I thought it would be good to create a single test class that tests them both.
First When I scheduled the job with
String jobId = System.schedule('ScheduledApexTest',CRON_EXP, new exampleClass()); and then stop the test with
Test.stopTest();, nothing happens. The TimesTriggered stays 0. This is kind of a separate issue, but I've been testing using the method below.
test.startTest(); SchedulableContext sc; exampleClass1 EC1 = new exampleClass1(); EC.execute(sc); SchedulableContext sc2; exampleClass2 EC2 = new exampleClass2(); EC2.execute(sc2); test.stopTest();
For some reason when I do this, it seems to run exampleClass1 twice and doesn't run exampleClass2. I also tried using only one schedulablecontext in both calls, but that gives a similar error.
Each of them works by themselves, but it acts weird when I do both together. Is this something that can be done, or do I just have to do this in two different test classes?