I'm having some problems trying to write a test class.
The issue is, the class which is being tested is composed of 5 methods that receive some information and use that information for querying. They're all very simple, here's an example:
public List<AgendamentoOrdemServico__c> getAgendamentoOrdemServico(String equipe, Datetime agStartDate, Datetime agEndDate, String tecnico, List<Boolean> lstStatus)
{
return [Select
Id,
Name,
Tecnico_DSM__c,
Tecnico_DSM__r.Name,
Agendado_Para__c,
Previsao_de_Termino__c,
Ordem_de_servico_DSM__c,
Ordem_de_servico_DSM__r.Name,
Ordem_de_servico_DSM__r.Produto_Instalado__c,
Ordem_de_servico_DSM__r.Defeito_Reclamado__c,
Ordem_de_servico_DSM__r.Nome_do_consumidor__c,
Ordem_de_servico_DSM__r.Telefone_consumidor__c,
Ordem_de_servico_DSM__r.Endereco__c,
Ordem_de_servico_DSM__r.Proximidade__c,
Motivo_do_Agendamento__c,
Atendente_DSM__c,
Justificativa_atraso_atendimento__c,
DescricaoAtividade__c,
RecordTypeId,
RecordType.DeveloperName,
isAtivo__c
From
AgendamentoOrdemServico__c
Where
Tecnico_DSM__r.Service_Group__c =: equipe
And Agendado_Para__c >=: Datetime.newInstance(agStartDate.year(), agStartDate.month(), agStartDate.day(), 0, 0, 0)
And Previsao_de_Termino__c <: Datetime.newInstance(agEndDate.year(), agEndDate.month(), agEndDate.day(), 23, 0, 0)
And Tecnico_DSM__c =: tecnico
And isAtivo__c IN: lstStatus
Order by Agendado_Para__c];
}
They all query differently, but that's the idea, receive some information, query and return.
I was not the one who wrote this class and neither am I allowed to mess around with it.
So, I started writing my test class for it, and here's what I got so far:
@isTest
private class AgendamentoOrdemServicoDAO_DSM_tst {
@TestSetup
public static void setup() {
// Here I inserted all the relevant data.
}
@isTest
public static void testGetAllAgendamentoOrdemServico() {
Test.startTest();
Datetime dateToday = Datetime.now().addDays(1);
AgendamentoOrdemServico__c agendamento = new AgendamentoOrdemServico__c();
List<AgendamentoOrdemServico__c> allAg = [
SELECT
Id,
Name,
Tecnico_DSM__c,
Tecnico_DSM__r.Name,
Agendado_Para__c,
Previsao_de_Termino__c,
Ordem_de_servico_DSM__c,
Ordem_de_servico_DSM__r.Name,
Ordem_de_servico_DSM__r.Produto_Instalado__c,
Ordem_de_servico_DSM__r.Defeito_Reclamado__c,
Ordem_de_servico_DSM__r.Nome_do_consumidor__c,
Ordem_de_servico_DSM__r.Telefone_consumidor__c,
Ordem_de_servico_DSM__r.Endereco__c,
Ordem_de_servico_DSM__r.Proximidade__c,
Motivo_do_Agendamento__c,
Atendente_DSM__c,
Justificativa_atraso_atendimento__c,
DescricaoAtividade__c,
RecordTypeId,
RecordType.DeveloperName,
isAtivo__c
FROM
AgendamentoOrdemServico__c
WHERE
Tecnico_DSM__r.Service_Group__c =: [SELECT id FROM Service_Group__c LIMIT 1].id
And Agendado_Para__c >=: dateToday
And Previsao_de_Termino__c <: Datetime.newInstance(dateToday.year(), dateToday.month(), dateToday.addDays(1).day(), 0, 0 , 0)
And isAtivo__c =: true
ORDER by Tecnico_DSM__r.Name, Agendado_Para__c
];
System.assert(allAg.size() > 0, 'Não trouxe agendamento.');
Test.stopTest();
}
Problem is, IT WORKS, but it doesn't really cover anything. I'm kind of new to test classes, I've done some tests for classes that actually did something other than just querying, and I'm having massive problems getting this one to cover ANYTHING at all.