Stack Exchange
System.LimitException: Too many DML rows: 10001
Does anyone know why i get: 

System.LimitException: Too many DML rows: 10001  Stack Trace:
  Class.CreateInvoice.: line 36, column 1
  Class.CreateInvoiceTestClass.testData: line 57, column 1

    @isTest(SeeAllData=true) 
public class CreateInvoiceTestClass{

    // Creating Test Data
   @isTest public static void testData(){

        Account account = new Account(Name = 'TestAccount1');  
        insert account;

        List<Training__c> trainingList = new List<Training__c>();
        for(integer counter=0;counter<20;counter++){

            Training__c trainingRecord = new Training__c();
            trainingRecord.name = 'TestRecord'+counter;
            trainingRecord.Startdatum__c = System.today().addDays(+2);
            trainingRecord.factuur_bedrijf__c = account.Id;
            trainingList.add(trainingRecord);
        }
        insert trainingList;

         List<Facturatie__c> facturatieList = new List<Facturatie__c>();
        for(integer counter=0;counter<20;counter++){

            Facturatie__c facturatieRecord = new Facturatie__c();
            facturatieRecord.name = 'TestRecord'+counter;
            facturatieRecord.Factuur_Bedrag__c = 1000;
            facturatieRecord.Training__c = trainingList[counter].Id;
            facturatieList.add(facturatieRecord);
        }

       for(integer counter=0;counter<20;counter++){

            Facturatie__c facturatieRecord = new Facturatie__c();
            facturatieRecord.name = 'TestRecord2'+counter;
            facturatieRecord.Factuur_Bedrag__c = 1000;
            facturatieRecord.Training__c = trainingList[counter].Id;
            facturatieList.add(facturatieRecord);
        }

       insert facturatieList;


        List<Cursist__c> cursistList = new List<Cursist__c>();
        for(integer counter=0;counter<20;counter++){

            Cursist__c cursistRecord = new Cursist__c();           
            cursistRecord.Training__c = trainingList[counter].Id;
            cursistRecord.Prijs_training__c = 10;
            cursistRecord.korting__c = 10;
            cursistRecord.CreatedDate = System.today();
            cursistList.add(cursistRecord);
        }
        insert cursistList;

       system.debug(facturatieList[0].Account__c);
       Test.StartTEst();
       CreateInvoice createInv = new CreateInvoice();
       Test.stopTest();

       System.assertEquals(facturatieList[0].Account__c,null);

    }

}

Class being tested
public class CreateInvoice{

    public CreateInvoice(){

        List<Training__c> trainingList = new List<Training__c>();
        List<Facturatie__c> facturatieList = new List<Facturatie__c>();

        try {
        trainingList = [SELECT id , NAME, Startdatum__c,factuur_bedrijf__c,
                          (SELECT Cursist_Prijs__c, Training__c, Cursist__c,CreatedDate,Prijs_training__c,
                           korting__c,Id 
                           FROM Trainingen_Volgen__r ) 
                       FROM  Training__c 
                       WHERE id NOT IN (SELECT  Training__c FROM Facturatie__c)];
        }catch (Exception e) {
            System.debug('The following exception has occurred' + e.getMessage() +
                         'At line number :' + e.getLineNumber() + 'Error' +
                         e.getStackTraceString());
        }              
        if(!trainingList.IsEmpty()){

            for(Training__c trainingRecord : trainingList){

                if(!trainingRecord.Trainingen_Volgen__r.IsEmpty()){

                    for(Cursist__c cursistRecord : trainingRecord.Trainingen_Volgen__r){

                        Facturatie__c facturatieRecord = checkDate(cursistRecord,trainingRecord);
                        facturatieList.add(facturatieRecord);
                    }
                }   
            }

            if(!facturatieList.IsEmpty()){  
               try {
                   insert facturatieList;
                }catch (Exception e) {
                    System.debug('The following exception has occurred' + e.getMessage() +
                                 'At line number :' + e.getLineNumber() + 'Error' +
                                 e.getStackTraceString());
                }   

            }
        }   
    }

    public Facturatie__c checkDate(Cursist__c cursistRecord,Training__c trainingRecord){

        if(cursistRecord != null && trainingRecord != null){
            Date todaysDate = system.today();

            if( todaysDate.addDays(-21) >= trainingRecord.Startdatum__c 
                && todaysDate >= cursistRecord.CreatedDate 
                && todaysDate.addDays(-1) >= trainingRecord.Startdatum__c){

                Facturatie__c facturatieRecord = new Facturatie__c();

                facturatieRecord.Training__c = trainingRecord.Id;   
                facturatieRecord.Factuur_Datum__c = todaysDate;  
                facturatieRecord.Verval_datum__c = todaysDate.addDays(30);

                if(cursistRecord.Prijs_training__c != null &&  cursistRecord.korting__c != null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.Prijs_training__c - cursistRecord.korting__c;
                }else if(cursistRecord.Prijs_training__c != null && cursistRecord.korting__c == null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.Prijs_training__c;
                }else if(cursistRecord.Prijs_training__c == null && cursistRecord.korting__c != null){
                    facturatieRecord.Factuur_Bedrag__c = cursistRecord.korting__c ;
                }

                facturatieRecord.Korting__c =  cursistRecord.korting__c;
                facturatieRecord.cursist_prijs__c= cursistRecord.Cursist_Prijs__c ;
                facturatieRecord.Contactpersoon__c = cursistRecord.Cursist__c;
                facturatieRecord.Account__c = trainingRecord.factuur_bedrijf__c; 

                return facturatieRecord;
            }
        }

        return null;
    }
}


First of all, you shouldn't set the (SeeAllData=true). With this, you can't control the data tested. It depends on the data in your current org.

In addition to @MartinLezer comments, remove seeAllData=true and secondly, then you will not need to call CreateInvoice class.

Is in your CreateInvoice() Constructor you are doing Insert in for Loop? That might be Case

The error message says it... The limit exception is thrown in the CreateInvoice on the line 36. :-)

It appears you're creating too many records. Perhaps there are child records created during your test?

You are calling your main class CreateInvoice from your test class, with SeeAllData=true, and creating test data yourself. This is contradiction. Why are you calling createinvoice() then?

When i remove (SeeAllData=true) I only get coverage till line 20 from for(trainin__C I get no coverage

coverage issues relate to not mocking other objects needed by logic
