[SalesForce] How separation of Test Class can solve 101 SOQL Queries Limit Exceeded Error

Recently one of my colleagues was trying to deploy to production some opportunity trigger activation, but during validation deployment two of ten test methods from TestMyMysteriousApexClass failed with Failure Message: "System.LimitException: Too many SOQL queries: 101".

To investigate this, I have separated these two test methods from other in separate TestDebug class.

However, to my great surprise, these two test methods haven't failed in a separate test class even if that opportunity trigger has active status.

So I just removed those two methods from my TestMyMysteriousApexClass and saved them in TestMyMysteriousApexClassAdditionalTestMethods.

Can anyone explain me how this could be possible at all?

How separation of Test Class TestMyMysteriousApexClass to two distint test classes can solve 101 SOQL Queries Limit Exceeded Error?

Isn't each test method a separate transaction?

Isn't SOQL Queries Limit counted for each test method separately?

Update: It seems that main culprit here is 'public' directive in the beginning of the class:

@isTest
public class TestMyMysteriousApexClass {
// should be:
//private class TestMyMysteriousApexClass {

    private static final String SOME_OBSCURE_STRING_CONSTANT_1 ='Some Obscure String Value 1';
    private static final String SOME_OBSCURE_STRING_CONSTANT_2 ='Some Obscure String Value 2';
    private static final String SOME_OBSCURE_STRING_CONSTANT_3 ='Some Obscure String Value 3';
    private static final String SOME_OBSCURE_STRING_CONSTANT_4 ='Some Obscure String Value 4';
    private static final String SOME_OBSCURE_STRING_CONSTANT_5 ='Some Obscure String Value 5';
    private static final String SOME_OBSCURE_STRING_CONSTANT_6 ='Some Obscure String Value 6';
    private static final String SOME_OBSCURE_STRING_CONSTANT_7 ='Some Obscure String Value 7';
    private static final List<String> someObscureStringList = new List<String>{SOME_OBSCURE_STRING_CONSTANT_1, SOME_OBSCURE_STRING_CONSTANT_2, SOME_OBSCURE_STRING_CONSTANT_3, SOME_OBSCURE_STRING_CONSTANT_4, SOME_OBSCURE_STRING_CONSTANT_5, SOME_OBSCURE_STRING_CONSTANT_6, SOME_OBSCURE_STRING_CONSTANT_7};
    private static final Decimal someObscureDecimal = 5.9;
    private static final Integer SOME_OBSCURE_INTEGER_CONSTANT_1 = 10;
    private static final Integer SOME_OBSCURE_INTEGER_CONSTANT_2 = 10;
    private static final String SOME_OBSCURE_STRING_CONSTANT_8 = 'Some Obscure String Value 8';
    private static final String SOME_OBSCURE_STRING_CONSTANT_9 = 'Some Obscure String Value 9';
    private static final String SOME_OBSCURE_STRING_CONSTANT_10 = 'Some Obscure String Value 10';
    private static final String SOME_OBSCURE_STRING_CONSTANT_11 = 'Some Obscure String Value 11';

    private static SomeObscureCustomObject1__c soco1Instance;
    private static SomeObscureCustomObject2__c soco2Instance1;
    private static SomeObscureCustomObject2__c soco2Instance2;
    private static User testUser;
    private static Opportunity opportunity;
    private static SomeObscureCustomObject3__c soco3Instance;
    private static Account testAccount;
    private static SomeObscureCustomObject4__c soco4Instance;
    private static List<SomeObscureCustomObject2__c> testsoco2Instance1List = new List<SomeObscureCustomObject2__c>();

    private static void setup() {
        setup( false );
    }

    private static void setup( Boolean someObscureBooleanParameter ){
        testUser = TestingUtils.createUser('someStrangeValue', TestingUtils.SYS_ADMIN_PROFILE_ID, true);
        System.runAs(testUser){
            testAccount = TestingUtils.createAccount();
            testAccount.someObscureSyncronizationField1__c = '12345';
            testAccount.someObscureSyncronizationDetector__c = true;
            update testAccount;

            opportunity = TestingUtils.createOpportunities( 1, false )[0];
            opportunity.AccountId = testAccount.Id;
            opportunity.customOppStringField1__c = UserInfo.getLastName() + ',' + Userinfo.getFirstName();
            opportunity.customOppStringField2__c = UserInfo.getLastName() + ',' + Userinfo.getFirstName();
            opportunity.customOppBooleanField__c = someObscureBooleanParameter;
            insert opportunity;


            soco4Instance = new SomeObscureCustomObject4__c( Name = SOME_OBSCURE_STRING_CONSTANT_10 );
            soco4Instance.Opportunity__c = opportunity.Id;
            soco4Instance.CurrencyIsoCode = testingUtils.CURRENCY_ISO_CODE_GBP;

            insert soco4Instance;

            soco3Instance = new SomeObscureCustomObject3__c();
            soco3Instance.Name = SOME_OBSCURE_STRING_CONSTANT_11;
            soco3Instance.RecordTypeId = testingUtils.SOCO3_OBSCURE_RECORD_TYPE_ID;
            soco3Instance.SomeObscureCustomObject4__c = soco4Instance.Id;
            soco3Instance.someObscureDecimal__c = 0;
            soco3Instance.someObscureDecimal_to_Consultant__c = 0;
            soco3Instance.soco3SomeStringField__c = SOME_OBSCURE_STRING_CONSTANT_8;
            soco3Instance.Opportunity__c = opportunity.Id;
            soco3Instance.CurrencyIsoCode = testingUtils.CURRENCY_ISO_CODE_USD;

            insert soco3Instance;

            soco2Instance1 = TestingUtils.createSoco2Instance1( soco4Instance.Id, UserInfo.getUserId(), false );
            soco2Instance1.SomeObscureCustomObject3__c = soco3Instance.Id;
            soco2Instance1.Name = SOME_OBSCURE_STRING_CONSTANT_9;
            testsoco2Instance1List.add( soco2Instance1 );

            soco2Instance2 = TestingUtils.createSoco2Instance1( soco4Instance.Id, UserInfo.getUserId(), false );
            soco2Instance2.SomeObscureCustomObject3__c = soco3Instance.Id;
            soco2Instance2.Name = SOME_OBSCURE_STRING_CONSTANT_9;
            soco2Instance2.Non_Billable__c = true;
            testsoco2Instance1List.add( soco2Instance2 );

            insert testsoco2Instance1List;

            soco1Instance = new SomeObscureCustomObject1__c();
            soco1Instance.someUserIdField__c = Userinfo.getUserId();
            insert soco1Instance;

        }
    }


    private static testmethod void testUpdateTypeForSomeObscureCustomObject6s(){
        testingUtils.avoidGovernorLimit = true;
        setup( true );

        System.runAs(testUser){
            final Date testDate = Date.newInstance(2012, 2, 13);
            List<SomeObscureCustomObject5__c> newSomeObscureCustomObject5s = new List<SomeObscureCustomObject5__c>();

            for( Integer i = 0; i < SOME_OBSCURE_INTEGER_CONSTANT_1; i++ ) {
                Date newDate = testDate.addDays(i*7);
                SomeObscureCustomObject5__c newSomeObscureCustomObject5 = new SomeObscureCustomObject5__c();
                newSomeObscureCustomObject5.Status__c = SomeObscureCustomObject5Services.STATUS_CONSTANT_1;
                newSomeObscureCustomObject5.SomeObscureCustomObject1__c = soco1Instance.Id;
                newSomeObscureCustomObject5.DateField1__c = newDate;
                newSomeObscureCustomObject5.SomeObscureCustomObject2__c = soco2Instance1.Id;
                newSomeObscureCustomObject5.IntegerField1__c = 7;
                newSomeObscureCustomObject5.IntegerField2__c = 7;
                newSomeObscureCustomObject5.IntegerField3__c = 7;
                newSomeObscureCustomObject5.IntegerField4__c = 7;
                newSomeObscureCustomObject5.IntegerField5__c = 7;
                newSomeObscureCustomObject5.CurrencyIsoCode = TestingUtils.CURRENCY_ISO_CODE_USD;

                newSomeObscureCustomObject5s.add( newSomeObscureCustomObject5 );
            }

            insert newSomeObscureCustomObject5s;
            SomeObscureCustomObject6Services.createStagingSomeObscureCustomObject5(newSomeObscureCustomObject5s);
            List<SomeObscureCustomObject6__c> testResultCustomObject6s = [ SELECT Id, AnotherStringField__c, Opportunity__c, Name,Some_Integer_Field_1__c, Some_Integer_Field_2__c
                                                          FROM SomeObscureCustomObject6__c
                                                          WHERE Opportunity__c = : opportunity.Id];

            System.assertEquals (testResultCustomObject6s.size(), SOME_OBSCURE_INTEGER_CONSTANT_1*5);// * 5 days that are filled in

            for (SomeObscureCustomObject6__c SomeObscureCustomObject6Item : testResultCustomObject6s){
                System.assertEquals (SomeObscureCustomObject6Item.AnotherStringField__c, SomeObscureCustomObject6Services.SomeObscureCustomObject5_LOI_TEXT);
                System.assert (SomeObscureCustomObject6Item.Name.contains(SomeObscureCustomObject6Services.SomeObscureCustomObject5_LOI_TEXT));
                System.assertEquals (SomeObscureCustomObject6Item.Some_Integer_Field_1__c, 0);
                System.assertEquals (SomeObscureCustomObject6Item.Some_Integer_Field_2__c, 0);
            }

            Test.startTest();

                soco2Instance2.Non_Billable__c = false;
                update soco2Instance2;

                soco3Instance = [SELECT Id, Name, someObscureDecimal__c, someObscureDecimal_to_Consultant__c
                           FROM SomeObscureCustomObject3__c
                           WHERE Id =:soco3Instance.Id];
                soco3Instance.someObscureDecimal__c = someObscureDecimal;
                soco3Instance.someObscureDecimal_to_Consultant__c = someObscureDecimal*10;
                update soco3Instance;

                opportunity.customOppBooleanField__c = false;

                SomeObscureCustomObject6Services.updateTypeForSomeObscureCustomObject6s(new Map<id, Opportunity>{opportunity.Id => opportunity});

                testResultCustomObject6s = [SELECT Id, AnotherStringField__c, Opportunity__c, Name, Some_Integer_Field_1__c, Some_Integer_Field_2__c
                                     FROM SomeObscureCustomObject6__c
                                     WHERE Opportunity__c = : opportunity.Id];
            Test.stopTest();

            System.assertEquals (testResultCustomObject6s.size(), SOME_OBSCURE_INTEGER_CONSTANT_1*5);// * 5 days that are filled in

            for (SomeObscureCustomObject6__c SomeObscureCustomObject6Item : testResultCustomObject6s){
                System.assertEquals (SomeObscureCustomObject6Item.AnotherStringField__c, SomeObscureCustomObject6Services.SomeObscureCustomObject5_TEXT);
                System.assert (!SomeObscureCustomObject6Item.Name.contains(SomeObscureCustomObject6Services.SomeObscureCustomObject5_LOI_TEXT) && SomeObscureCustomObject6Item.Name.contains(SomeObscureCustomObject6Services.SomeObscureCustomObject5_TEXT));
                System.assertEquals (SomeObscureCustomObject6Item.Some_Integer_Field_1__c, someObscureDecimal);
                System.assertEquals (SomeObscureCustomObject6Item.Some_Integer_Field_2__c, someObscureDecimal*10);
            }
        }
    }

    private static testmethod void testCreateStagingSomeObscureCustomObject5s (){
        testingUtils.avoidGovernorLimit = true;
        setup();

        System.runAs(testUser){

            final Date testDate = Date.newInstance(2012, 2, 13);
            List<SomeObscureCustomObject5__c> newSomeObscureCustomObject5s = new List<SomeObscureCustomObject5__c>();
            List<SomeObscureCustomObject5__c> newSomeOtherObscureCustomObject5s = new List<SomeObscureCustomObject5__c>();
            List<SomeObscureCustomObject5__c> allSomeObscureCustomObject5s = new List<SomeObscureCustomObject5__c>();

            for( Integer i = 0; i < SOME_OBSCURE_INTEGER_CONSTANT_1; i++ ){
                Date newDate = testDate.addDays(i*7);
                SomeObscureCustomObject5__c newSomeObscureCustomObject5 = new SomeObscureCustomObject5__c();
                newSomeObscureCustomObject5.Status__c = SomeObscureCustomObject5Services.STATUS_CONSTANT_1;
                newSomeObscureCustomObject5.SomeObscureCustomObject1__c = soco1Instance.Id;
                newSomeObscureCustomObject5.DateField1__c = newDate;
                newSomeObscureCustomObject5.SomeObscureCustomObject2__c = soco2Instance1.Id;
                newSomeObscureCustomObject5.IntegerField1__c = 7;
                newSomeObscureCustomObject5.IntegerField2__c = 7;
                newSomeObscureCustomObject5.IntegerField3__c = 7;
                newSomeObscureCustomObject5.IntegerField4__c = 7;
                newSomeObscureCustomObject5.IntegerField5__c = 7;
                newSomeObscureCustomObject5.StringField1__c = SOME_OBSCURE_STRING_CONSTANT_1;
                newSomeObscureCustomObject5.StringField2__c = SOME_OBSCURE_STRING_CONSTANT_2;
                newSomeObscureCustomObject5.StringField3__c = SOME_OBSCURE_STRING_CONSTANT_3;
                newSomeObscureCustomObject5.StringField4__c = SOME_OBSCURE_STRING_CONSTANT_4;
                newSomeObscureCustomObject5.StringField5__c = SOME_OBSCURE_STRING_CONSTANT_5;
                newSomeObscureCustomObject5.StringField6__c = SOME_OBSCURE_STRING_CONSTANT_6;
                newSomeObscureCustomObject5.StringField7__c = SOME_OBSCURE_STRING_CONSTANT_7;
                newSomeObscureCustomObject5.CurrencyIsoCode = testingUtils.CURRENCY_ISO_CODE_USD;

                newSomeObscureCustomObject5s.add( newSomeObscureCustomObject5 );
                allSomeObscureCustomObject5s.add( newSomeObscureCustomObject5 );
            }

            for( Integer i = 0; i < SOME_OBSCURE_INTEGER_CONSTANT_2; i++ ){
                Date newDate = testDate.addDays(i*7);
                SomeObscureCustomObject5__c newSomeObscureCustomObject5 = new SomeObscureCustomObject5__c();
                newSomeObscureCustomObject5.SomeObscureCustomObject1__c = soco1Instance.Id;
                newSomeObscureCustomObject5.DateField1__c = newDate;
                newSomeObscureCustomObject5.SomeObscureCustomObject2__c = soco2Instance2.Id;
                newSomeObscureCustomObject5.IntegerField1__c = 7;
                newSomeObscureCustomObject5.IntegerField2__c = 7;
                newSomeObscureCustomObject5.IntegerField3__c = 7;
                newSomeObscureCustomObject5.IntegerField4__c = 7;
                newSomeObscureCustomObject5.IntegerField5__c = 7;
                newSomeObscureCustomObject5.StringField1__c = SOME_OBSCURE_STRING_CONSTANT_1;
                newSomeObscureCustomObject5.StringField2__c = SOME_OBSCURE_STRING_CONSTANT_2;
                newSomeObscureCustomObject5.StringField3__c = SOME_OBSCURE_STRING_CONSTANT_3;
                newSomeObscureCustomObject5.StringField4__c = SOME_OBSCURE_STRING_CONSTANT_4;
                newSomeObscureCustomObject5.StringField5__c = SOME_OBSCURE_STRING_CONSTANT_5;
                newSomeObscureCustomObject5.StringField6__c = SOME_OBSCURE_STRING_CONSTANT_6;
                newSomeObscureCustomObject5.StringField7__c = SOME_OBSCURE_STRING_CONSTANT_7;
                newSomeObscureCustomObject5.CurrencyIsoCode = testingUtils.CURRENCY_ISO_CODE_USD;

                newSomeOtherObscureCustomObject5s.add( newSomeObscureCustomObject5 );
                allSomeObscureCustomObject5s.add( newSomeObscureCustomObject5 );
            }

            insert allSomeObscureCustomObject5s;

            Test.startTest();
                SomeObscureCustomObject6Services.createStagingSomeObscureCustomObject5( allSomeObscureCustomObject5s );
            Test.stopTest();

            List<SomeObscureCustomObject6__c> actualCustomObject6s = [ SELECT Id, String_Field_1__c, Name, Date_Field_1__c, Some_Id_Field__c, String_Field_2__c, OwnerId,
                                                                Consultant_soco2Instance1_Name__c, customOppStringField1__c, customOppStringField2__c, Opportunity_Owner__c,
                                                                Some_Id_Field_2__c, CurrencyIsoCode, AccountId__c
                                                      FROM SomeObscureCustomObject6__c
                                                      WHERE Some_Id_Field__c IN : new Map<Id, SomeObscureCustomObject5__c>( newSomeObscureCustomObject5s ).keySet()
                                                      ORDER BY Date_Field_1__c ASC ];

            List<SomeObscureCustomObject6__c> otherCustomObject6s = [ SELECT Some_Integer_Field_1__c, Some_Integer_Field_2__c, AnotherStringField__c, CurrencyIsoCode, AccountId__c
                                                          FROM SomeObscureCustomObject6__c
                                                          WHERE Some_Id_Field__c IN : new Map<Id, SomeObscureCustomObject5__c>( newSomeOtherObscureCustomObject5s ).keySet()
                                                          ORDER BY Date_Field_1__c ASC ];

            Map<Id, List<SomeObscureCustomObject6__c>> actualCustomObject6sMap = new Map<Id, List<SomeObscureCustomObject6__c>>();

            for( SomeObscureCustomObject6__c CustomObject6Item : otherCustomObject6s ){
                System.assertEquals( opportunity.AccountId, CustomObject6Item.AccountId__c );
                System.assertEquals( 0, CustomObject6Item.Some_Integer_Field_1__c );
                System.assertEquals( 0, CustomObject6Item.Some_Integer_Field_2__c );
                System.assertEquals( SomeObscureCustomObject6Services.SomeObscureCustomObject5_TEXT_OTHER_CONSTANT, CustomObject6Item.AnotherStringField__c );
                System.assertEquals( testingUtils.CURRENCY_ISO_CODE_USD, CustomObject6Item.CurrencyIsoCode );
            }

            for( SomeObscureCustomObject6__c CustomObject6 : actualCustomObject6s ){
                System.assertEquals( opportunity.AccountId, CustomObject6.AccountId__c );
                if( actualCustomObject6sMap.containsKey( CustomObject6.Some_Id_Field__c ) )
                    actualCustomObject6sMap.get( CustomObject6.Some_Id_Field__c ).add( CustomObject6 );
                else
                    actualCustomObject6sMap.put( CustomObject6.Some_Id_Field__c, new List<SomeObscureCustomObject6__c>{ CustomObject6 } );
            }

            System.assertEquals( SOME_OBSCURE_INTEGER_CONSTANT_1 * 5 , actualCustomObject6s.size() );
            System.assertEquals( SOME_OBSCURE_INTEGER_CONSTANT_2 * 5 , otherCustomObject6s.size() );

            Date expectedDate = testDate;

            for( SomeObscureCustomObject5__c newSomeObscureCustomObject5 : newSomeObscureCustomObject5s ){
                List<SomeObscureCustomObject6__c> CustomObject6s = actualCustomObject6sMap.get( newSomeObscureCustomObject5.Id );

                System.assertEquals( 5, CustomObject6s.size() );

                for( SomeObscureCustomObject6__c CustomObject6 : CustomObject6s ){
                     String CustomObject6Name = expectedDate.Month() + '/' + expectedDate.day() + '/' + expectedDate.year() + ' - ' + SomeObscureCustomObject6Services.SomeObscureCustomObject5_TEXT + ' - ' + CustomObject6.String_Field_1__c;

                     System.assertEquals( CustomObject6Name, CustomObject6.Name );
                     System.assertEquals( Userinfo.getUserId(), CustomObject6.Some_Id_Field_2__c );
                     System.assertEquals( expectedDate, CustomObject6.Date_Field_1__c );
                     System.assertEquals( SOME_OBSCURE_STRING_CONSTANT_9, CustomObject6.Consultant_soco2Instance1_Name__c );
                     System.assertEquals( UserInfo.getLastName() + ',' + Userinfo.getFirstName(), CustomObject6.customOppStringField1__c );
                     System.assertEquals( UserInfo.getLastName() + ',' + Userinfo.getFirstName(), CustomObject6.customOppStringField2__c );
                     System.assertEquals( testUser.FirstName  + ' ' + testUser.LastName, CustomObject6.Opportunity_Owner__c );
                     System.assertEquals( Userinfo.getUserId(), CustomObject6.OwnerId );
                     System.assertEquals( testingUtils.CURRENCY_ISO_CODE_USD, CustomObject6.CurrencyIsoCode );

                     expectedDate = expectedDate.addDays( 1 );
                }
                for( Integer i = 1; CustomObject6s.size() > i; i++ ){
                    System.assertEquals( someObscureStringList[i], CustomObject6s[i].String_Field_2__c );
                }
                expectedDate = expectedDate.addDays( 2 );
            }
        }
    }

    private static testmethod void testFilterSomeObscureCustomObject5RecordsOnInsert (){
        setup();
        final Integer NUM_RECORDS = 10;
        final Date testDate = Date.newInstance(2012, 2, 13);
        List<SomeObscureCustomObject5__c> newSomeObscureCustomObject5s = new List<SomeObscureCustomObject5__c>();

        for( Integer i = 0; i < NUM_RECORDS; i++ ){
            Date newDate = testDate.addDays( i * 7 );
            SomeObscureCustomObject5__c newSomeObscureCustomObject5 = new SomeObscureCustomObject5__c();
            newSomeObscureCustomObject5.Status__c = SomeObscureCustomObject5Services.STATUS_CONSTANT_1;
            newSomeObscureCustomObject5.SomeObscureCustomObject1__c = soco1Instance.Id;
            newSomeObscureCustomObject5.DateField1__c = newDate;
            newSomeObscureCustomObject5.SomeObscureCustomObject2__c = soco2Instance1.Id;
            newSomeObscureCustomObject5.IntegerField1__c = 7;
            newSomeObscureCustomObject5.IntegerField2__c = 7;
            newSomeObscureCustomObject5.IntegerField3__c = 7;
            newSomeObscureCustomObject5.IntegerField4__c = 7;
            newSomeObscureCustomObject5.IntegerField5__c = 7;
            newSomeObscureCustomObject5.Boolean_Some_Status_Field__c = false;
            newSomeObscureCustomObject5.CurrencyIsoCode = testingUtils.CURRENCY_ISO_CODE_GBP;
            newSomeObscureCustomObject5s.add(newSomeObscureCustomObject5);
        }
        insert newSomeObscureCustomObject5s;

        for(Integer i=0; i< NUM_RECORDS/2 ; i++)
            newSomeObscureCustomObject5s[i].Boolean_Some_Status_Field__c = true;

        List<SomeObscureCustomObject5__c> actualSomeObscureCustomObject5s;
        Test.startTest();
            actualSomeObscureCustomObject5s = SomeObscureCustomObject6Services.filterSomeObscureCustomObject5Records( null, new Map<Id, SomeObscureCustomObject5__c> ( newSomeObscureCustomObject5s ) );
        Test.stopTest();

        System.assertEquals( NUM_RECORDS/2 , actualSomeObscureCustomObject5s.size() );
    }

    private static testmethod void testFilterSomeObscureCustomObject5RecordsOnUpdate (){
        setup();
        final Integer NUM_RECORDS = 10;
        final Date testDate = Date.newInstance(2012, 2, 13);
        List<SomeObscureCustomObject5__c> newSomeObscureCustomObject5s = new List<SomeObscureCustomObject5__c>();

        for( Integer i = 0; i < NUM_RECORDS; i++ ){
            Date newDate = testDate.addDays( i * 7 );
            SomeObscureCustomObject5__c newSomeObscureCustomObject5 = new SomeObscureCustomObject5__c();
            newSomeObscureCustomObject5.Status__c = SomeObscureCustomObject5Services.STATUS_CONSTANT_1;
            newSomeObscureCustomObject5.SomeObscureCustomObject1__c = soco1Instance.Id;
            newSomeObscureCustomObject5.DateField1__c = newDate;
            newSomeObscureCustomObject5.SomeObscureCustomObject2__c = soco2Instance1.Id;
            newSomeObscureCustomObject5.IntegerField1__c = 7;
            newSomeObscureCustomObject5.IntegerField2__c = 7;
            newSomeObscureCustomObject5.IntegerField3__c = 7;
            newSomeObscureCustomObject5.IntegerField4__c = 7;
            newSomeObscureCustomObject5.IntegerField5__c = 7;
            newSomeObscureCustomObject5.Boolean_Some_Status_Field__c = false;
            newSomeObscureCustomObject5.CurrencyIsoCode = testingUtils.CURRENCY_ISO_CODE_USD;

            newSomeObscureCustomObject5s.add(newSomeObscureCustomObject5);
        }
        insert newSomeObscureCustomObject5s;

        List<SomeObscureCustomObject5__c> testSomeObscureCustomObject5s = newSomeObscureCustomObject5s.deepClone(true);

        for(Integer i=0; i< NUM_RECORDS/2 ; i++)
            testSomeObscureCustomObject5s[i].Boolean_Some_Status_Field__c = true;

        List<SomeObscureCustomObject5__c> actualSomeObscureCustomObject5s;
        Test.startTest();
            actualSomeObscureCustomObject5s = SomeObscureCustomObject6Services.filterSomeObscureCustomObject5Records( new Map<Id, SomeObscureCustomObject5__c> ( newSomeObscureCustomObject5s ), new Map<Id, SomeObscureCustomObject5__c> ( testSomeObscureCustomObject5s ) );
        Test.stopTest();

        System.assertEquals( NUM_RECORDS/2 , actualSomeObscureCustomObject5s.size() );
    }
// some other obscure test methods after that....

so, when I change visibility of test class from public to private, 101 SOQL Queries LIMIT Exception disappears also…

So, the methods which are failing if they are together with other methods with 'public' test class are testFilterSomeObscureCustomObject5RecordsOnInsert and testFilterSomeObscureCustomObject5RecordsOnUpdate/

New Update.

Today I tried again and it seems that file was failing even though had 'private' declaration in the beginning.
I have looked then at the version number thoroughly again, and it seems that API version matters, so actually TestMyMysteriousApexClass has API Version number not 26 but 23, while TestDebug has API Version number 28.

It seems George S. was most close to the solution in his comment

Does TestMyMysteriousApexClass have the same API Version as TestDebug? –  George S. 

However, I still don't really understand how API Version number of a class can impact on SOQL Queries limit calculation…

Best Answer

EDIT:

It seems George S. was most close to the solution in his comment

Does TestMyMysteriousApexClass have the same API Version as TestDebug? – George S.

However, I still don't really understand how API Version number of a class can impact on SOQL Queries limit calculation...

Because classes saved with API v 23 and lower act as if they have IsTest(SeeAllData=true) ;)


In no specific order...

  • Is @SeeAllData present in the test? Is the trigger calling classes that have different with/without sharing (this thing has tri-state logic: with, without and blank; blank means "inherit from parent that called my methods))? I think SeeAllData is sometimes needed when testing Opportunities because the Pricebook object is nasty.
  • Does the code (triggers/workflows) have anything User-specific? You probably have same Profiles, but what about roles, groups, maybe even amount of owned opportunities (just guessing what the trigger might be doing)? Some hierarchy custom setting maybe? For consistent (if cumbersome) results you should be testing with System.runAs(user-generated-in-test-class) where possible.
  • Now that the trigger is activated - what happens your colleague will try to run all tests in production?
  • Anything random happening in the tests? ;)
Related Topic