• Paolo Magliocco 18
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi. I'm writing test class and this cover 15% of code.
Can someone help me to complete test class?
Thank you.

This is code of class :

public class AddQuoteLineItemCtrl {
    
    private final Quote quote{get; set;}
    public integer pageNum {get; set;}
    public ID IDToQuery {get; set;}
    public string nameToQuery {get; set;}
    public ID IDToQuery2 {get; set;}
    public string nameToQuery2 {get; set;}
    public ID standardPricebookID {get; set;}
    public List<PricebookEntry> queryspbe {get; set;}
    public List<Product2> queryprodotti {get; set;}
    public List<Product2> queryprodottifiltrata {get; set;}
    public List<Edizione__c> queryedizioni {get; set;}
    public List<Edizione__c> queryedizionifiltrata {get; set;}
    public Product2 prodottoselezionato {get; set;}
    public Edizione__c edizioneselezionata {get;set;}
    public decimal IVA {get; set;}
    public decimal prezzodilistino {get; set;}
    public integer partecipazionipresenti {get; private set;}
    public integer partecipazionidisponibili {get; set;}
    public Boolean numeropartecipazioninonvalido {get; set;}
    public integer numeropartecipazioni{get;
                                        set{
                                            integer pdisp = partecipazionidisponibili;
                                            if (value <= pdisp){
                                                numeropartecipazioni = value;
                                            } else {
                                                numeropartecipazioninonvalido = TRUE;
                                                numeropartecipazioni = 0;
                                            }
                                        }
                                       }
    public boolean partecipazionisettate {get; set;}
    public List<Partecipazione__c> listapartecipazioni {get; set;}
    public QuoteLineItem qli {get; set;}
    
    public AddQuoteLineItemCtrl(ApexPages.StandardController Ctrl){
        
        if (!Test.isRunningTest()) {ctrl.addfields(new list<string>{'Account.Percentuale_IVA_def__c', 'Opportunity.Account.Id'});}
        this.quote = (Quote)Ctrl.getRecord();
        
        PageNum = 0;
        prodottoselezionato = new Product2();
        edizioneselezionata = new Edizione__c(Ha_Partecipazioni__c=FALSE);
        nameToQuery = '';
        partecipazionipresenti=0;
        partecipazionidisponibili=0;
        numeropartecipazioninonvalido = FALSE;
        partecipazionisettate = FALSE;
        listapartecipazioni = new List<Partecipazione__c>();
        qli = new QuoteLineItem();
        
        //queryprodotti = [SELECT Id, Name, Valuta__c, ProductCode, IsActive, Tipo_prezzo__c, Prezzo_di_listino__c, IVA__c, Tipologia_Prodotto__c, Unit_di_vendita__c FROM Product2 ORDER BY Name ASC];
        standardPricebookID = [SELECT Id FROM Pricebook2 WHERE isStandard=TRUE LIMIT 1][0].Id;
        queryspbe = [SELECT Id, UnitPrice, Product2.Id, Pricebook2.Id FROM PricebookEntry WHERE Pricebook2.Id=:standardPricebookID];
        List<ID> p2list = new List<ID>();
        for (PricebookEntry pbe : queryspbe) {
            p2list.add(pbe.Product2.Id);
        }
        
        queryprodotti = [SELECT Id, Name, A_Catalogo__c, Ha_Edizioni__c, ProductCode, IsActive, Tipo_prezzo__c, Tipologia_Prodotto_def__c, IVA__c, Unit_di_vendita__c FROM Product2 WHERE Id IN :p2list ORDER BY Name ASC];
        queryprodottifiltrata=queryprodotti.clone();
        
        
        
    }
    
    public pageReference search(){
        queryprodottifiltrata.clear();
        for (Product2 p : queryprodotti){
            if (p.Name.toLowerCase().contains(nametoquery.toLowerCase())){
                queryprodottifiltrata.add(p);
            }
        }
        return NULL;
    }
    
    public pageReference search2(){
        queryedizionifiltrata.clear();
        for (Edizione__c p : queryedizioni){
            if (p.Name.toLowerCase().contains(nametoquery2.toLowerCase())){
                queryedizionifiltrata.add(p);
            }
        }
        return NULL;
    }
    
    public pageReference selectname(){
        
        for (Product2 p : queryprodotti){
            if (p.Id == IDtoQuery){
                prodottoselezionato = p;
                break;
            }
        }
        for (PricebookEntry pbe : queryspbe) {
            if (pbe.Product2Id == prodottoselezionato.Id){
                prezzodilistino = pbe.UnitPrice;
            }
        }
        if (prodottoselezionato.IVA__c != quote.Account.Percentuale_IVA_def__c){
            IVA = quote.Account.Percentuale_IVA_def__c;
        } else if (prodottoselezionato.IVA__c != NULL) {
            IVA = prodottoselezionato.IVA__c;
        }
        if (!prodottoselezionato.Ha_Edizioni__c){
            pagenum++;
            pagenum++;
            return NULL;
        }
        queryedizioni = [SELECT Id, Name, Ha_Partecipazioni__c, Data_inizio__c, Data_fine__c, Durata__c, Massimo_numero_di_partecipanti__c, Prodotto__c, Posti_ricevuti__c, Citt_Sede__c, Stato_Provincia_Sede__c, Sede__c FROM Edizione__c WHERE Prodotto__c =: IDtoQuery];
        queryedizionifiltrata = queryedizioni.clone();
        pageNum++;
        return NULL;
    }
    
    public pageReference selectname2(){
        for (Edizione__c e : queryedizioni){
            if (e.Id == IdtoQuery2){
                edizioneselezionata = e;
                break;
            }
        }
        qli.UnitPrice = prezzodilistino;
        partecipazionipresenti = [SELECT Id FROM Partecipazione__c WHERE Edizione__r.Id=:edizioneselezionata.Id].size();
        integer pmax;
        if (edizioneselezionata.Massimo_numero_di_partecipanti__c==NULL){
            pmax=12;
        } else {
            pmax=edizioneselezionata.Massimo_numero_di_partecipanti__c.intValue();
        }
        partecipazionidisponibili = pmax - partecipazionipresenti;
        if (partecipazionidisponibili <= 0) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, 'L\'edizione selezionata non ha posti disponibili (il numero di partecipazioni presenti ha raggiunto il numero massimo di partecipazioni impostato per l\'edizione). Selezionare un\'altra edizione, oppure aumentare il numero di posti disponibili per l\'edizione interessata.'));
            return NULL;
        } else {
        pagenum++;
        return NULL;
        }
    }
    
    public pageReference next(){
        qli.QuoteId=quote.Id;
        qli.Product2Id=prodottoselezionato.Id;
        if(edizioneselezionata.Id != NULL){
            qli.Edizione__c=edizioneselezionata.Id;
        }
        ID pbeID = NULL; 
        for (PriceBookEntry pbe : queryspbe){
        if(pbe.Product2.id==qli.Product2Id){
            pbeID=pbe.ID;
        }        
        }
        qli.PriceBookEntryId=pbeID;
        pagenum++;
        return NULL;
    }
    
    public pageReference salva1(){
        qli.QuoteId=quote.Id;
        qli.Product2Id=prodottoselezionato.Id;
        if(edizioneselezionata.Id != NULL){
            qli.Edizione__c=edizioneselezionata.Id;
        }
        ID pbeID = NULL;
        for (PriceBookEntry pbe : queryspbe){
        if(pbe.Product2.id==qli.Product2Id){
            pbeID=pbe.ID;
        }        
        }
        qli.PriceBookEntryId=pbeID;
        try{
            insert qli;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getmessage()));
            return NULL;
        }
        return new PageReference('/' + quote.Id);
    }
    
    public pageReference salva2(){
    
        try{
            insert qli;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getmessage()));
            return NULL;
        }
    
        List<Partecipazione__c> listapartecipazioni2 = new List<Partecipazione__c>();
        for (Partecipazione__c p : listapartecipazioni){
            p.Voce_Preventivo__c=qli.Id;
            p.Edizione__c=edizioneselezionata.Id;
            p.Account__c = quote.Opportunity.Account.Id;
            p.Stato__c = 'Partecipante';
            listapartecipazioni2.add(p);
            }
        
        try{
            insert listapartecipazioni2;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getmessage()));
            return NULL;
        }
        
        return new PageReference('/' + quote.Id);
        
    }
    
    public pageReference previous0(){
        return new PageReference('/' + quote.Id);
    }
    
    public pageReference previous(){
        if (pagenum==1){
            prodottoselezionato = new Product2();
            IVA = NULL;
            prezzodilistino = NULL;
        }
        partecipazionisettate = FALSE;
        pagenum--;
        return NULL;
    }
    
    public pageReference previous2(){
        edizioneselezionata=new Edizione__c(Ha_Partecipazioni__c=TRUE);
        pagenum--;
        pagenum--;
        return NULL;
    }
    
    public pageReference creapartecipazioni(){
        if (numeropartecipazioninonvalido) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Il numero delle partecipazioni da creare deve essere minore o uguale al numero di partecipazioni disponibili per questa edizione.'));
            numeropartecipazioninonvalido=FALSE;
            return NULL;
        }
        partecipazionisettate = TRUE;
        listapartecipazioni.clear();
        for (integer i=1; i<=numeropartecipazioni; i++) {
            listapartecipazioni.add(new Partecipazione__c());
        }
        return NULL;
    }

}


This is code of test class :

@isTest

public class AddQuoteLineItemCtrl_Test {
    static testMethod void Costruttore_Test()
    {

 /******************************************************************* INIZIO DEL TEST   ***********************************************************************************************/      
 
      test.startTest();
      
      Account acc = new Account();
      acc.name='Test';
      acc.billingStreet='via delle rose';
      acc.billingCity='Milano';
      acc.billingState='Giappone';
      acc.billingCountry='Italy';
      insert acc;
        
      Opportunity opp = new Opportunity();
      opp.Accountid = acc.id;
      opp.Name = 'test';
      opp.StageName = 'Prospecting';
      opp.CloseDate = date.today();
      opp.Type = 'New Client';
      opp.NextStep = 'Test';
      opp.LeadSource = 'Business Development';
      insert opp;
      
      Product2 prod = new Product2 ();
      prod.name='test';
      prod.IsActive=true;
      insert prod;
      List<Product2> l_prod = new List<Product2>(); 
      l_prod.add(prod);

      Id pricebookId = Test.getStandardPricebookId();
      List<PricebookEntry> l_pbe = new List<PricebookEntry>();
      PricebookEntry pbe = new PricebookEntry ();
      pbe.Product2Id=prod.Id;
      pbe.IsActive=true;
      pbe.UnitPrice=1;
      pbe.isStandard=true;
      pbe.Pricebook2Id=pricebookId;
      insert pbe;
      l_pbe.add(pbe);
      
      
      List<Quote> l_off = new List<Quote>();
      
      Quote offerta = new Quote();
      offerta.Name = 'I trulli';
      offerta.N_Offerta__c = '1000000';
      offerta.OpportunityId = opp.id;
      offerta.Pricebook2Id = pricebookId ;
      offerta.Training__c = TRUE;
      insert offerta;
    
     Date data = date.newInstance(2999,02,36);  
     Edizione__c edz = New Edizione__c();
     edz.Name = 'Test';
     edz.data_inizio__c = data;
     edz.data_fine__c = data+3;
     edz.motivo_stato__c='edizione erogata';
     insert edz;
     List<Edizione__c> l_edz = new List<Edizione__c>();
     l_edz.add(edz);
     List<Partecipazione__c> l_part = new List<Partecipazione__c>();
      
      ApexPages.StandardController controller = new ApexPages.StandardController(offerta);
      AddQuoteLineItemCtrl stdController = new AddQuoteLineItemCtrl(controller);
      
      stdController.search();
      stdController.search2();
      
      
      
      

/******************************************************************* FINE DEL TEST   ***********************************************************************************************/      
 
   test.stopTest();

   }
  
 }
Hi I'm writing a test class but It covers the code only 65% of class.
Can someone help me?

Code of class is this :

public class InvioFatturaCtrl {


    public String users { get; set; }
    public String toAddresses {get; set;}
    public String ccAddresses {get; set;}
    public String ccnAddresses {get; set;}
    public String testomail {get; set;}
    public String emailUserTo {get; set;}
    public String emailUserCc {get; set;}
    public String emailUserCcn {get; set;}
    public Boolean emailSent {get; private set;}
    public PageReference thePDF {public get; public set;}
    
    public Fattura__c fatt {get; set;}
    public Integer pageNum { get; set; }
   // public List<QuoteLineItem> l_qtl{get; set;}
   // public List<Partecipazione__c> l_ptz{get; set;}
  //  public List<Riga_Fattura__c> l_rfat{get; set;}
    public Integer dim_qtl = 0;
    public Pagereference Fattura {get;set;}


    public String getCcAddresses() {
        return null;
    }

    


    List<SelectOption> Options= new List<SelectOption>();
    public String scelta {get;set;}  // conterrà il valore selezionato/scelto da Options
    
    public List<SelectOption> getOptions(){   // mi popola la variabile Options con i 2 valori si no 
       List<SelectOption> opt = new List<SelectOption>();
       opt.add(new SelectOption('NO','NO'));
       opt.add(new SelectOption('SI','SI'));
       return opt;
    }
   
   
    public void registerUser() {  // incremento il numero della pagina da visualizzare ogni volta che clicco sul tasto AVANTI
      
      pageNum++;
    }

    
    
     public InvioFatturaCtrl(ApexPages.StandardController stdcontroller) {
     pageNum = 1;
     this.fatt = (Fattura__c)stdController.getRecord();
     this.fatt = [Select id,name,Preventivo__r.Training__c,Preventivo__r.Consulenza__c, Preventivo__r.Opportunity.AccountId,Preventivo__r.Opportunity.Account.Owner.name, Preventivo__r.Opportunity.Account.Descrizione_IVA_def__c,Preventivo__r.Opportunity.Account.Note_esenzione_IVA__c, Preventivo__r.Banca__r.name,Preventivo__r.Banca__r.Conto_corrente__c, Preventivo__r.Banca__r.ABI__c, Preventivo__r.Banca__r.CAB__c , Preventivo__r.Banca__r.IBAN__c, Preventivo__r.Opportunity.Account.Name,Preventivo__r.Opportunity.Account.BillingStreet,Preventivo__r.Opportunity.Account.BillingCity,Preventivo__r.Opportunity.Account.BillingState,Preventivo__r.Opportunity.Account.BillingPostalCode, Preventivo__r.Opportunity.Account.Partita_IVA__c , preventivo__c  from fattura__c where id =:stdController.getRecord().id];
     if(fatt.Preventivo__r.Training__c == true){
            fattura = page.Fattura_Standard;
        }
        else if (fatt.Preventivo__r.Consulenza__c == true){
            fattura = page.Fattura_Consulenza;
        } 
        system.debug('****test'+fattura );
     }
    
    
    public String addEmailAddress(String email, String emailAddresses) {
        
        if(String.isBlank(email)){
          return emailAddresses;
         }
         
        if(emailAddresses == null) {
          emailAddresses = '';
         }
         
        List<String> listOfEmail = emailAddresses.split(';');
        listOfEmail.add(email);
        
        Set<String> listOfUniqueEmail = new Set<String>();
        listOfUniqueEmail.addAll(listOfEmail);
        emailAddresses = '';
        for(String e : listOfUniqueEmail)
            if(String.isNotBlank(e)){
                emailAddresses += e + ';';
            }
        emailAddresses = emailAddresses.removeEnd(';');
        return emailAddresses;
    }
 
 
    
    public void addToAddresses()  { 
        toAddresses  = addEmailAddress(emailUserTo, toAddresses);   
    }
    
    public void addCcAddresses()  { 
       ccAddresses  = addEmailAddress(emailUserCc, ccAddresses);   
    }
   
    public void addCcnAddresses() { 
       ccnAddresses = addEmailAddress(emailUserCcn, ccnAddresses); 
    } 
    
   
   
   public Attachment createPDF() {
        thePDF = Fattura;
        thePDF.getParameters().put('Id', fatt.Id);
        system.debug('***thePDF'+thePDF);
        attachment qd=new attachment();
        if(!Test.isRunningTest()){            qd.Body = thePDF.getContentAsPDF();        } else {
            Blob blab = Blob.valueOf('Test Data');
            qd.Body = blab;
        }
        system.debug('***qd.Body'+qd.Body);
      qd.ContentType = 'application/pdf';     
      qd.Name = fatt.name +'.pdf';
      return qd;
      }
      

 public pageReference invia() {
        Boolean validate = true;
        if(String.isBlank(toAddresses)) {
            validate = false;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Specificare indirizzo e-mail'));
        }
        if(String.isBlank(testomail)) {
            validate = false;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Specificare testo e-mail'));
        }
        
        List<String> toAddressesList  = new List<String>();
        List<String> ccAddressesList  = new List<String>();
        List<String> ccnAddressesList = new List<String>();
        if(!String.isBlank(toAddresses))  toAddressesList  = toAddresses.split(';');
        if(!String.isBlank(ccAddresses))  ccAddressesList  = ccAddresses.split(';');
        if(!String.isBlank(ccnAddresses)) ccnAddressesList = ccnAddresses.split(';');
        
       // if(!validate) { return Apexpages.currentPage(); }
        //  else{ return NULL;}
                
        String subject = 'Fattura da inviare'; // ' + fatt.Preventivo__r.Opportunity.Account.name + ' - ' + fatt.Name;
    //  testomail = 'questo è il testo della mail';
        String body = testomail /*.replaceAll('\n','<br/>')*/;
        
        Messaging.EmailFileAttachment allegatoEmail = new Messaging.EmailFileAttachment();
        Attachment qd = createPDF();
        system.debug('****test'+qd );
        
        allegatoEmail.setBody(qd.Body);
        allegatoEmail.setFileName(qd.Name);
        allegatoEmail.setContentType(qd.ContentType);
        system.debug('****test'+allegatoEmail );

        list<Messaging.EmailFileAttachment> allegatiEmail = new list<Messaging.EmailFileAttachment>();
        allegatiEmail.add(allegatoEmail);
        
        
        
        messaging.SingleEmailMessage mail = new messaging.SingleEmailMessage();
            mail.setCcAddresses(ccAddressesList);
            mail.setToAddresses(toAddressesList);
            mail.setBccAddresses(ccnAddressesList);
            mail.setSubject(subject);
            mail.setHTMLBody(testomail);
            mail.setFileAttachments(allegatiEmail);
            system.debug('****test'+mail );
            list<messaging.SingleEmailMessage> mails = new list<messaging.SingleEmailMessage>{mail};
           
        
        emailSent = TRUE;
        List<messaging.sendemailresult> results = messaging.sendEmail(mails);
       
        
        qd.ParentId = fatt.Id;
        List<Attachment>qds = new List<Attachment>();
        qds.add(qd);
        try{
            insert qds;
          //  quo.Status = 'Attiva';
          //  update quo;
        }catch (DMLexception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Eccezione DML nell\'upload dell\'allegato: ' + e));
        }
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Allegato caricato!'));
         
        //return NULL;
        return new PageReference('/'+fatt.id);

    }
 
 }


Code of test class is this : 

@isTest

public class Invio_FatturaCtrl_Test {
    static testMethod void Costruttore_Test()
    {

 /*******************************************************************  START TEST   ***********************************************************************************************/      
 
      test.startTest();
      
      List<SelectOption> Options= new List<SelectOption>();
      
      Account acc = new Account();
      acc.name='Test Account';
      acc.billingStreet='via bo';
      acc.billingCity='Torino';
      acc.billingState='Ecuador';
      acc.billingCountry='Italy';
      insert acc;
        
      Opportunity opp = new Opportunity();
      opp.Accountid = acc.id;
      opp.Name = 'test';
      opp.StageName = 'Prospecting';
      opp.CloseDate = date.today();
      opp.Type = 'New Client';
      opp.NextStep = 'Test';
      opp.LeadSource = 'Business Development';
      insert opp;
      
      Product2 prod = new Product2 ();
      prod.name='test';
      prod.IsActive=true;
      insert prod;

      Id pricebookId = Test.getStandardPricebookId();
      PricebookEntry pbe = new PricebookEntry ();
      pbe.Product2Id=prod.Id;
      pbe.IsActive=true;
      pbe.UnitPrice=1;
      pbe.Pricebook2Id=pricebookId;
      insert pbe;
      
      Quote offerta = new Quote();
      offerta.Name = 'soldi';
      offerta.N_Offerta__c = '9cento';
      offerta.OpportunityId = opp.id;
      offerta.Pricebook2Id = pricebookId ;
      insert offerta;
        
      Fattura__c fat = new Fattura__c();
      fat.Preventivo__c = offerta.id;
      insert fat;
      List<Fattura__c> l_fat = new List<Fattura__c>();
      l_fat.add(fat);
      
      
      messaging.SingleEmailMessage messg_mail = new messaging.SingleEmailMessage();
      //mail.setCcAddresses(ccAddressesList);
      Messaging.EmailFileAttachment allegatoEmail = new Messaging.EmailFileAttachment();
      attachment alleg =new attachment();
      alleg.ParentId = fat.id ;
      alleg.Name = 'non mi interessa';
      alleg.Body = Blob.valueOf('/services/data/v38.0/sobjects/Attachment/'+fat.id+'/Body');
      insert alleg;
      
      List<messaging.SingleEmailMessage> l_mail = new list<messaging.SingleEmailMessage>{messg_mail};
      Set<String> l_mail_univoche = new Set<String>();
      List<Messaging.EmailFileAttachment> l_allegati = new list<Messaging.EmailFileAttachment>();
      
      List<String> toAddressesList  = new List<String>();
      List<String> ccAddressesList  = new List<String>();
      List<String> ccnAddressesList = new List<String>();
    
      List<String> l_indirizzi_dest  = new List<String>();
      List<String> l_indirizzi_copia  = new List<String>();
      List<String> l_indir_copianascosta = new List<String>();
      String scelta = 'scegli me';
      
      
     ApexPages.StandardController controller = new ApexPages.StandardController(fat);
     InvioFatturaCtrl stdController = new InvioFatturaCtrl(controller);
     
     String email = 'senza soldi non si canta messa';
     String emailAddresses = 'babbo@natale.it';
     stdController.getCcAddresses();
     stdController.getOptions();
     stdController.registerUser();
     stdController.addEmailAddress(email,emailAddresses);
     stdController.addToAddresses(); 
     stdController.addCcAddresses();
     stdController.addCcnAddresses();
     stdController.invia();
     stdController.createPDF();

 


/******************************************************************* FINISH TEST   ***********************************************************************************************/      
 
   test.stopTest();

   }
  
 }
I 'm writing this class with its test class and I can save my code because there aren't errors but test class don't cover code of the class.
Can we help me to solve problems? 
Thank you.

This is Class : 

public class Ordine_Aziendale {


   public Quote preventivo{get; set;}
   public List<Account> account{get; set;}
   public Opportunity opportunita{get; set;}
   public List<QuoteLineItem> qtl{get; set;}
   public Integer cont{get;set;}
   
   public User utente{get; set;}  
    
    public Ordine_Aziendale(ApexPages.StandardController stdcontroller) {
    
      this.preventivo = (Quote)stdController.getRecord();
    
   // Product2 p2 = new Product2 (name='test');
      //  insert p2;
        
        qtl = [SELECT id , product2.id, product2.name, product2.ProductCode, Quantity, UnitPrice FROM QuoteLineItem  WHERE Quote.id =: preventivo.id];
        cont = qtl.size();
        
      // account = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.id];
     // opportunita = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.AccountId];
    }
}


This is my test class :

@isTest
public class Ordine_Aziendale_Test {
    static testMethod void Costruttore_Test()
    {
     
 /************************* START TEST   *************************************/      
 
     test.startTest();
      
     List<Account> l_acc = new List<Account>();
     Account acc = new Account(name='Test Account', billingStreet='Test', billingCity='Test', billingState='Test', billingCountry='Test');
     insert acc;
     l_acc.add(acc);
  
     List<Opportunity> l_opp = new List<Opportunity>();
     Opportunity opp = new Opportunity();
     opp.Accountid = acc.id;
     opp.Name = 'test';
     opp.StageName = 'Prospecting';
     opp.CloseDate = date.today();
     opp.Type = 'New Client';
     opp.NextStep = 'Test';
     opp.LeadSource = 'Business Development';
     insert opp;
     l_opp.add(opp);
      
     List<Quote> l_preventivi = new List<Quote>();  
     Quote preventivo = new Quote(Name = 'Test',OpportunityId = opp.id, N_Offerta__c = 'test');
     insert preventivo;
     l_preventivi.add(preventivo);
     
     // Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
        
     Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
     insert pb;
        
      Product2 prod = new Product2(Name = 'Anti-infectives 2007', Family = 'Best Practices', IsActive = true);
      insert prod;

     List<QuoteLineItem> l_qtl = new List<QuoteLineItem>();
     QuoteLineItem qtl = new quotelineitem(quoteid = preventivo.id,quantity = 1,unitprice = 1); 
     insert qtl;
     l_qtl.add(qtl);

      ApexPages.StandardController controller = new ApexPages.StandardController(preventivo);
      Ordine_Aziendale stdController = new Ordine_Aziendale(controller);



/********************************************** FINISH TEST   *************************************/      
 
   test.stopTest();

   }
  
 }

 
Hi I'm writing a test class but It covers the code only 65% of class.
Can someone help me?

Code of class is this :

public class InvioFatturaCtrl {


    public String users { get; set; }
    public String toAddresses {get; set;}
    public String ccAddresses {get; set;}
    public String ccnAddresses {get; set;}
    public String testomail {get; set;}
    public String emailUserTo {get; set;}
    public String emailUserCc {get; set;}
    public String emailUserCcn {get; set;}
    public Boolean emailSent {get; private set;}
    public PageReference thePDF {public get; public set;}
    
    public Fattura__c fatt {get; set;}
    public Integer pageNum { get; set; }
   // public List<QuoteLineItem> l_qtl{get; set;}
   // public List<Partecipazione__c> l_ptz{get; set;}
  //  public List<Riga_Fattura__c> l_rfat{get; set;}
    public Integer dim_qtl = 0;
    public Pagereference Fattura {get;set;}


    public String getCcAddresses() {
        return null;
    }

    


    List<SelectOption> Options= new List<SelectOption>();
    public String scelta {get;set;}  // conterrà il valore selezionato/scelto da Options
    
    public List<SelectOption> getOptions(){   // mi popola la variabile Options con i 2 valori si no 
       List<SelectOption> opt = new List<SelectOption>();
       opt.add(new SelectOption('NO','NO'));
       opt.add(new SelectOption('SI','SI'));
       return opt;
    }
   
   
    public void registerUser() {  // incremento il numero della pagina da visualizzare ogni volta che clicco sul tasto AVANTI
      
      pageNum++;
    }

    
    
     public InvioFatturaCtrl(ApexPages.StandardController stdcontroller) {
     pageNum = 1;
     this.fatt = (Fattura__c)stdController.getRecord();
     this.fatt = [Select id,name,Preventivo__r.Training__c,Preventivo__r.Consulenza__c, Preventivo__r.Opportunity.AccountId,Preventivo__r.Opportunity.Account.Owner.name, Preventivo__r.Opportunity.Account.Descrizione_IVA_def__c,Preventivo__r.Opportunity.Account.Note_esenzione_IVA__c, Preventivo__r.Banca__r.name,Preventivo__r.Banca__r.Conto_corrente__c, Preventivo__r.Banca__r.ABI__c, Preventivo__r.Banca__r.CAB__c , Preventivo__r.Banca__r.IBAN__c, Preventivo__r.Opportunity.Account.Name,Preventivo__r.Opportunity.Account.BillingStreet,Preventivo__r.Opportunity.Account.BillingCity,Preventivo__r.Opportunity.Account.BillingState,Preventivo__r.Opportunity.Account.BillingPostalCode, Preventivo__r.Opportunity.Account.Partita_IVA__c , preventivo__c  from fattura__c where id =:stdController.getRecord().id];
     if(fatt.Preventivo__r.Training__c == true){
            fattura = page.Fattura_Standard;
        }
        else if (fatt.Preventivo__r.Consulenza__c == true){
            fattura = page.Fattura_Consulenza;
        } 
        system.debug('****test'+fattura );
     }
    
    
    public String addEmailAddress(String email, String emailAddresses) {
        
        if(String.isBlank(email)){
          return emailAddresses;
         }
         
        if(emailAddresses == null) {
          emailAddresses = '';
         }
         
        List<String> listOfEmail = emailAddresses.split(';');
        listOfEmail.add(email);
        
        Set<String> listOfUniqueEmail = new Set<String>();
        listOfUniqueEmail.addAll(listOfEmail);
        emailAddresses = '';
        for(String e : listOfUniqueEmail)
            if(String.isNotBlank(e)){
                emailAddresses += e + ';';
            }
        emailAddresses = emailAddresses.removeEnd(';');
        return emailAddresses;
    }
 
 
    
    public void addToAddresses()  { 
        toAddresses  = addEmailAddress(emailUserTo, toAddresses);   
    }
    
    public void addCcAddresses()  { 
       ccAddresses  = addEmailAddress(emailUserCc, ccAddresses);   
    }
   
    public void addCcnAddresses() { 
       ccnAddresses = addEmailAddress(emailUserCcn, ccnAddresses); 
    } 
    
   
   
   public Attachment createPDF() {
        thePDF = Fattura;
        thePDF.getParameters().put('Id', fatt.Id);
        system.debug('***thePDF'+thePDF);
        attachment qd=new attachment();
        if(!Test.isRunningTest()){            qd.Body = thePDF.getContentAsPDF();        } else {
            Blob blab = Blob.valueOf('Test Data');
            qd.Body = blab;
        }
        system.debug('***qd.Body'+qd.Body);
      qd.ContentType = 'application/pdf';     
      qd.Name = fatt.name +'.pdf';
      return qd;
      }
      

 public pageReference invia() {
        Boolean validate = true;
        if(String.isBlank(toAddresses)) {
            validate = false;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Specificare indirizzo e-mail'));
        }
        if(String.isBlank(testomail)) {
            validate = false;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Specificare testo e-mail'));
        }
        
        List<String> toAddressesList  = new List<String>();
        List<String> ccAddressesList  = new List<String>();
        List<String> ccnAddressesList = new List<String>();
        if(!String.isBlank(toAddresses))  toAddressesList  = toAddresses.split(';');
        if(!String.isBlank(ccAddresses))  ccAddressesList  = ccAddresses.split(';');
        if(!String.isBlank(ccnAddresses)) ccnAddressesList = ccnAddresses.split(';');
        
       // if(!validate) { return Apexpages.currentPage(); }
        //  else{ return NULL;}
                
        String subject = 'Fattura da inviare'; // ' + fatt.Preventivo__r.Opportunity.Account.name + ' - ' + fatt.Name;
    //  testomail = 'questo è il testo della mail';
        String body = testomail /*.replaceAll('\n','<br/>')*/;
        
        Messaging.EmailFileAttachment allegatoEmail = new Messaging.EmailFileAttachment();
        Attachment qd = createPDF();
        system.debug('****test'+qd );
        
        allegatoEmail.setBody(qd.Body);
        allegatoEmail.setFileName(qd.Name);
        allegatoEmail.setContentType(qd.ContentType);
        system.debug('****test'+allegatoEmail );

        list<Messaging.EmailFileAttachment> allegatiEmail = new list<Messaging.EmailFileAttachment>();
        allegatiEmail.add(allegatoEmail);
        
        
        
        messaging.SingleEmailMessage mail = new messaging.SingleEmailMessage();
            mail.setCcAddresses(ccAddressesList);
            mail.setToAddresses(toAddressesList);
            mail.setBccAddresses(ccnAddressesList);
            mail.setSubject(subject);
            mail.setHTMLBody(testomail);
            mail.setFileAttachments(allegatiEmail);
            system.debug('****test'+mail );
            list<messaging.SingleEmailMessage> mails = new list<messaging.SingleEmailMessage>{mail};
           
        
        emailSent = TRUE;
        List<messaging.sendemailresult> results = messaging.sendEmail(mails);
       
        
        qd.ParentId = fatt.Id;
        List<Attachment>qds = new List<Attachment>();
        qds.add(qd);
        try{
            insert qds;
          //  quo.Status = 'Attiva';
          //  update quo;
        }catch (DMLexception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Eccezione DML nell\'upload dell\'allegato: ' + e));
        }
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Allegato caricato!'));
         
        //return NULL;
        return new PageReference('/'+fatt.id);

    }
 
 }


Code of test class is this : 

@isTest

public class Invio_FatturaCtrl_Test {
    static testMethod void Costruttore_Test()
    {

 /*******************************************************************  START TEST   ***********************************************************************************************/      
 
      test.startTest();
      
      List<SelectOption> Options= new List<SelectOption>();
      
      Account acc = new Account();
      acc.name='Test Account';
      acc.billingStreet='via bo';
      acc.billingCity='Torino';
      acc.billingState='Ecuador';
      acc.billingCountry='Italy';
      insert acc;
        
      Opportunity opp = new Opportunity();
      opp.Accountid = acc.id;
      opp.Name = 'test';
      opp.StageName = 'Prospecting';
      opp.CloseDate = date.today();
      opp.Type = 'New Client';
      opp.NextStep = 'Test';
      opp.LeadSource = 'Business Development';
      insert opp;
      
      Product2 prod = new Product2 ();
      prod.name='test';
      prod.IsActive=true;
      insert prod;

      Id pricebookId = Test.getStandardPricebookId();
      PricebookEntry pbe = new PricebookEntry ();
      pbe.Product2Id=prod.Id;
      pbe.IsActive=true;
      pbe.UnitPrice=1;
      pbe.Pricebook2Id=pricebookId;
      insert pbe;
      
      Quote offerta = new Quote();
      offerta.Name = 'soldi';
      offerta.N_Offerta__c = '9cento';
      offerta.OpportunityId = opp.id;
      offerta.Pricebook2Id = pricebookId ;
      insert offerta;
        
      Fattura__c fat = new Fattura__c();
      fat.Preventivo__c = offerta.id;
      insert fat;
      List<Fattura__c> l_fat = new List<Fattura__c>();
      l_fat.add(fat);
      
      
      messaging.SingleEmailMessage messg_mail = new messaging.SingleEmailMessage();
      //mail.setCcAddresses(ccAddressesList);
      Messaging.EmailFileAttachment allegatoEmail = new Messaging.EmailFileAttachment();
      attachment alleg =new attachment();
      alleg.ParentId = fat.id ;
      alleg.Name = 'non mi interessa';
      alleg.Body = Blob.valueOf('/services/data/v38.0/sobjects/Attachment/'+fat.id+'/Body');
      insert alleg;
      
      List<messaging.SingleEmailMessage> l_mail = new list<messaging.SingleEmailMessage>{messg_mail};
      Set<String> l_mail_univoche = new Set<String>();
      List<Messaging.EmailFileAttachment> l_allegati = new list<Messaging.EmailFileAttachment>();
      
      List<String> toAddressesList  = new List<String>();
      List<String> ccAddressesList  = new List<String>();
      List<String> ccnAddressesList = new List<String>();
    
      List<String> l_indirizzi_dest  = new List<String>();
      List<String> l_indirizzi_copia  = new List<String>();
      List<String> l_indir_copianascosta = new List<String>();
      String scelta = 'scegli me';
      
      
     ApexPages.StandardController controller = new ApexPages.StandardController(fat);
     InvioFatturaCtrl stdController = new InvioFatturaCtrl(controller);
     
     String email = 'senza soldi non si canta messa';
     String emailAddresses = 'babbo@natale.it';
     stdController.getCcAddresses();
     stdController.getOptions();
     stdController.registerUser();
     stdController.addEmailAddress(email,emailAddresses);
     stdController.addToAddresses(); 
     stdController.addCcAddresses();
     stdController.addCcnAddresses();
     stdController.invia();
     stdController.createPDF();

 


/******************************************************************* FINISH TEST   ***********************************************************************************************/      
 
   test.stopTest();

   }
  
 }
I 'm writing this class with its test class and I can save my code because there aren't errors but test class don't cover code of the class.
Can we help me to solve problems? 
Thank you.

This is Class : 

public class Ordine_Aziendale {


   public Quote preventivo{get; set;}
   public List<Account> account{get; set;}
   public Opportunity opportunita{get; set;}
   public List<QuoteLineItem> qtl{get; set;}
   public Integer cont{get;set;}
   
   public User utente{get; set;}  
    
    public Ordine_Aziendale(ApexPages.StandardController stdcontroller) {
    
      this.preventivo = (Quote)stdController.getRecord();
    
   // Product2 p2 = new Product2 (name='test');
      //  insert p2;
        
        qtl = [SELECT id , product2.id, product2.name, product2.ProductCode, Quantity, UnitPrice FROM QuoteLineItem  WHERE Quote.id =: preventivo.id];
        cont = qtl.size();
        
      // account = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.id];
     // opportunita = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.AccountId];
    }
}


This is my test class :

@isTest
public class Ordine_Aziendale_Test {
    static testMethod void Costruttore_Test()
    {
     
 /************************* START TEST   *************************************/      
 
     test.startTest();
      
     List<Account> l_acc = new List<Account>();
     Account acc = new Account(name='Test Account', billingStreet='Test', billingCity='Test', billingState='Test', billingCountry='Test');
     insert acc;
     l_acc.add(acc);
  
     List<Opportunity> l_opp = new List<Opportunity>();
     Opportunity opp = new Opportunity();
     opp.Accountid = acc.id;
     opp.Name = 'test';
     opp.StageName = 'Prospecting';
     opp.CloseDate = date.today();
     opp.Type = 'New Client';
     opp.NextStep = 'Test';
     opp.LeadSource = 'Business Development';
     insert opp;
     l_opp.add(opp);
      
     List<Quote> l_preventivi = new List<Quote>();  
     Quote preventivo = new Quote(Name = 'Test',OpportunityId = opp.id, N_Offerta__c = 'test');
     insert preventivo;
     l_preventivi.add(preventivo);
     
     // Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
        
     Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
     insert pb;
        
      Product2 prod = new Product2(Name = 'Anti-infectives 2007', Family = 'Best Practices', IsActive = true);
      insert prod;

     List<QuoteLineItem> l_qtl = new List<QuoteLineItem>();
     QuoteLineItem qtl = new quotelineitem(quoteid = preventivo.id,quantity = 1,unitprice = 1); 
     insert qtl;
     l_qtl.add(qtl);

      ApexPages.StandardController controller = new ApexPages.StandardController(preventivo);
      Ordine_Aziendale stdController = new Ordine_Aziendale(controller);



/********************************************** FINISH TEST   *************************************/      
 
   test.stopTest();

   }
  
 }