[SalesForce] System.LimitException: Too many query rows: 50001 for Test Class

I have come across this error in production but in a test class where I am defining 5 rows only , how come I'm facing this error ?
Also there was no error in QA but error in Dev and Prod.

List<Object__c> objList = new List<Object__c>();
    Object__c obj = new Object__c(Delivery_Location__c='Dalian',Ref__c = '13',Volume__c=1, Grad_Volume__c=1,Month__c='January',Year__c='2013',Country__c='ANZ');
    objList.add(obj);
insert objList;

Should I remove @isTest(seeAllData=true) ?

Please suggest.

Best Answer

Yes you should remove seeAllData=true and never use it again (Isolation of Test Data in Unit Tests). Instead create a test data directly in your test class and work only with that data. You have to assume that there is no data you can access in the production org.

Common Test Utility Classes for Test Data Creation.

In addition your code should respect system limits. Use Limits Class to access limits dynamically in apex.