0

Apex class:

public class GenRangoTarjeta_cls {// OJCB v 1.4 This class generates a range of cards concatenating the program code and country code 
      public static void addRangoTarjeta (Card_Rate__c rangs, String prefpro, String prepai, String country) { 
          rangs.Rango_inicial_Num__c = Long. valueOf (rangs.Rango_Inicial__c); 
          System.debug ('RankInicialnum:' + rangs.Rango_Inicial_Num__c); 
          rangs.Rango_Final_Num__c = Long.valueOf (rangs.Rango_Final__c); 
          System.debug ('FinalFinal Range:' + rangs.Rango_Final_Num__c); 
          rangs.Rango_Inicial__c = prefpro + prepai + rangs.Rango_Inicial__c; 
          System.debug ('Initial Rangeconcat:' + rangs.Rango_inicial__c); 
          rangs.Rango_Final__c = prefpro + prepai + rangs.Rango_Final__c;
          System.debug ('FinalConcat Range:' + rangs.Rango_Final__c);    
          rangs.Reference__c = prepai + prefpro + country; 
      } 
    }

Test Class:

@isTest
private class Test_GenRangoTarjeta_cls {//OJCB v 1.4 clase de pruebas para generar rangos
    public static testMethod void t1(){
        Tipo_Programa__c myTipoProg = new Tipo_Programa__c(Name='Programa de prueba', Pais__c='Guatemala', Programa__c='VB',Codigo_Pais__c='01');
        try {
            insert myTipoProg;
            system.debug ('\n\nEl tipo de programa:'+myTipoProg);
        } catch (System.DmlException e) {
            system.debug ('\n\nError t1 creando tipo programa: '+e);
        }
        Rango_Tarjetas__c myRango = new Rango_Tarjetas__c(Rango_Inicial__c='000011', Rango_Final__c='000015', Tipo_Programa__c=myTipoProg.Id);
        try {
            insert myRango;
            system.debug (myRango);
        } catch (System.DmlException e) {
            system.debug ('Errort1: '+e);
        }  
   } 
   public static testMethod void t2(){
        Tipo_Programa__c myTipoProg = new Tipo_Programa__c(Name='Programa de prueba', Pais__c='Guatemala', Programa__c='VB',Codigo_Pais__c='01');
        try {
            insert myTipoProg;
            system.debug ('\n\nEl tipo de programa:'+myTipoProg);
        } catch (System.DmlException e) {
            system.debug ('\n\nError t1 creando tipo programa: '+e);
        }
        Rango_Tarjetas__c myRango = new Rango_Tarjetas__c(Rango_Inicial__c='00000025', Rango_Final__c='00000040', Tipo_Programa__c=myTipoProg.Id);
        try {
            insert myRango;
            system.debug (myRango);
        } catch (System.DmlException e) {
            system.debug ('Errort2: '+e);
        } 
   } 
   public static testMethod void t3(){
        Tipo_Programa__c myTipoProg = new Tipo_Programa__c(Name='Programa de prueba', Pais__c='Guatemala', Programa__c='VB',Codigo_Pais__c='01');
        try {
            insert myTipoProg;
            system.debug ('\n\nEl tipo de programa:'+myTipoProg);
        } catch (System.DmlException e) {
            system.debug ('\n\nError t1 creando tipo programa: '+e);
        }
        Rango_Tarjetas__c myRango = new Rango_Tarjetas__c(Rango_Inicial__c='0000090', Rango_Final__c='0000080', Tipo_Programa__c=myTipoProg.Id);
        try {
            insert myRango;
            system.debug (myRango);
        } catch (System.DmlException e) {
            system.debug ('Errort3: '+e);
        }       
    }
    public static testMethod void t4(){
        Tipo_Programa__c myTipoProg = new Tipo_Programa__c(Name='Programa de prueba', Pais__c='Guatemala', Programa__c='VB',Codigo_Pais__c='01');
        try {
            insert myTipoProg;
            system.debug ('\n\nEl tipo de programa:'+myTipoProg);
        } catch (System.DmlException e) {
            system.debug ('\n\nError t1 creando tipo programa: '+e);
        }
        Rango_Tarjetas__c myRango = new Rango_Tarjetas__c(Rango_Inicial__c='000011', Rango_Final__c='000015', Tipo_Programa__c=myTipoProg.Id);
        try {
            insert myRango;
            system.debug (myRango);
        } catch (System.DmlException e) {
            system.debug ('Errort4: '+e);
        }
        Rango_Tarjetas__c myRango2 = new Rango_Tarjetas__c(Rango_Inicial__c='000012', Rango_Final__c='000014', Tipo_Programa__c=myTipoProg.Id);
        try {
            insert myRango2;
            system.debug (myRango2);
        } catch (System.DmlException e) {
            system.debug ('Errort4: '+e);
        }   
   }
   public static testMethod void t5(){
        Tipo_Programa__c myTipoProg = new Tipo_Programa__c(Name='Programa de prueba', Pais__c='Guatemala', Programa__c='VB',Codigo_Pais__c='01');
        try {
            insert myTipoProg;
            system.debug ('\n\nEl tipo de programa:'+myTipoProg);
        } catch (System.DmlException e) {
            system.debug ('\n\nError t1 creando tipo programa: '+e);
        }
        Rango_Tarjetas__c myRango = new Rango_Tarjetas__c(Rango_Inicial__c='000018', Rango_Final__c='000001', Tipo_Programa__c=myTipoProg.Id);
        try {
            insert myRango;
            system.debug (myRango);
        } catch (System.DmlException e) {
            system.debug ('Errort5: '+e);
        }          
   }

    }

Could you please help me in finding the issue. Thanks in advance.

1
  • 5
    Your test class doesn't call your code. How are you expecting it to be covered? Is there other code, such as a trigger, involved?
    – David Reed
    Nov 1, 2019 at 18:14

2 Answers 2

0

I observe that there is no explicit call to the addRangoTarjeta() which is the actual method that needs to be verified. How is the addRangoTarjeta() invoked anyway?

Ideally your test methods in the test class should be written as follows. Add the other methods accordingly I am only including t1() as an example.

@isTest
private class Test_GenRangoTarjeta_cls {

    public static testMethod void t1(){

        Card_Rate__c rangsInstance = new Card_Rate__c();

        test.startTest();

        //Invoke the rangs.Reference__c method to verify the behaviour
        GenRangoTarjeta_cls.addRangoTarjeta(
            rangsInstance,
            'prefpro string',       
            'prepai string',
            'country string'
        );

        test.stopTest();

        //Checking if the reference value is concatenated as expected
        System.assertEquals(
            'prefpro string' + 'prepai string' + 'country string', 
            rangsInstance.Reference__c);
        );
    }
}
-1
public static void testMethod t1 () {

should be

public static testmethod void t1 () {

And you're missing the explicit call to any part of the class you're trying to test. So follow what Sagar mentions above as well. Also, testmethod is depreciated and the preferred way is to use @isTest above methods as well as the test class.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_isTest.htm

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.