+ Start a Discussion
SolidLucasSolidLucas 

test class help

I want to create a test class for those methods someone could help me?

public void getAccounts(){

    String stringComplemento = '';
     string searchquery='SELECT name,id,Tipo_de_Documento__c,Temp_Cod_ERP__c,Raz_o_Social_SCC__c,'+
                        'Nome_fantasia_SCC__c,N_mero_do_Documento__c,Temp_Cod_Cliente__c, Cia__c,Ativo__c,CEP_SCC__c,Logradouro__c,Bairro_SCC__c,'+
                        'Cidade_SCC__c,UF_SCC__c,SituacaoCliente__c FROM Account ';
 
                    if(PesquisaString != '' && PesquisaString!=null){                           
                        stringComplemento = ' WHERE name LIKE '+ '\'%' +PesquisaString+'%\'';
                    }
                        
                     if(NomeFantasia != '' && NomeFantasia!=null){
                            if(stringComplemento!=''){
                                stringComplemento += ' and ';
                            }else{
                                stringComplemento += ' where ';
                            }
                            stringComplemento += ' Nome_fantasia_SCC__c LIKE '+ '\'%' +NomeFantasia+'%\'';  
                        }
         searchquery =  searchquery + stringComplemento;   
                Temp=searchquery + stringComplemento ;
                listAccPesquisa = Database.query(searchquery);
 
public void doSearch(){
   		 if(!verificarCampoValido(RazaoSocial) || 
   		 	!verificarCampoValido(NomeFantasia)|| 
   		 	!verificarCampoValido(PesquisaCodCliente) ||
   		 	!verificarCampoValido(PesquisaCodEndereco)||
   		 	!verificarCampoValido(NumeroDocumento)||
   		 	!verificarCampoValido(Cep)||
   		 	!verificarCampoValido(Logradouro)||
   		 	!verificarCampoValido(Bairro)||
   		 	!verificarCampoValido(Cidade)||
   		 	!verificarCampoValido(Uf)||
   		 	!verificarCampoValido(cia)||
   		 	!verificarCampoValido(tipoDocumento)){
		     getAccounts();
		     getCiaOptions();
   		 }else{
   		   ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,
   		   (msg!= null && msg != '')? msg : 'Necessario Preencher ao menos um campo');
           ApexPages.addmessage(msg); 	
   		 }
    }
  
    private boolean verificarCampoValido(String campo){
    	boolean retorno = campo == null || campo == '' || campo = true;
    	
    	if(!retorno){
    		if(campo.length() < 3){
	    	 msg = 'Necessario informar no minimo 3 caracteres para consulta';
	       	 retorno = true;
    		}
    	}
    	return retorno;
    }
  
    
   /*****************************************************
   *Metodo para fazer a selecao do tipo da cia no picklist
   *Method to include selecting the cia type into the picklist
   ******************************************************/
    public List<SelectOption> getCiaOptions() {
        List<SelectOption> CiaOptions = parameters.getListOptions('Organization');
        return CiaOptions;
        }
    }
PratikPratik (Salesforce Developers) 
Hi,

Here is the guide that you can refer to:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm

Guidelines for you code:

Code1:

Insert an account record and retrieve it through SOQL query.  Change the value of fields to cover both the if and else part of your code,

E.g. 
if(PesquisaString != '' && PesquisaString!=null)

Update the field PesquisaString to be null/blank and also to a non blank value. etc. same for other fields in IF .. Else condition.

Hope this will help you!

Thanks,
Pratik