function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
developer srideveloper sri 

Test class for Class

can someone please help me in writing test class for this class:

public with sharing class BigMachinecls { 

public static double getU(String BB, String Rools, String Foo, double qty, String teks){


double UQty = 0.0;

If ( (BB == null || BB == 'N') && (Rolls == null || Rolls == 'N') && (Foo == null || Foo == 'N') ){

UQty = qty /double.valueof(teks);

System.debug('@@@@@ inside getU method U : - Quantity - ' + UQty);


}
return UQty;

}//End of getU() method

public static double getMachineDetail( String machine1, String machineGroup, decimal qty, String checks){

double MachineDetailQuantity = 0;

If ( machine1.contains('tata') && (machine1.contains('Tek') || 
machine1.contains('X1')) && !machine1.contains('23HP') && 
!machine1.contains('125HP') && !machineGroup.contains('MECH_ALEN')){


MachineDetailQuantity = qty;

System.debug('@@@@@ inside getMachineDetail Qty : ' + MachineDetailQuantity );


}
return MachineDetailQuantity;

} // end of getMachineDetailQuantity method 


Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
digamber.prasaddigamber.prasad

Hi,

 

Below is test class with assertion as said by you:-

 

@isTest
private class BigMachinecls_Test {

    static testmethod void testBigMachinecls() {
        double dU = BigMachinecls.getU('N', 'N', 'N', double.valueOf('5.0'), '10.0');
        double dMacDet = BigMachinecls.getMachineDetail('tataTek', 'xyz', 5.0, 'test');
        system.debug('dU:-->' + dU);
        system.debug('dMacDet:-->' + dMacDet);
        system.assertequals(5.0,dMacDet,'dMacDet failure in test');
    }
}

 Let me know if you still have any issue.

All Answers

digamber.prasaddigamber.prasad

Hi,

 

Please try below test class. Also, please add system.asserts as per your requirement:-

 

@isTest
private class BigMachinecls_Test {

    static testmethod void testBigMachinecls() {
        double dU = BigMachinecls.getU('N', 'N', 'N', double.valueOf('5.0'), '10.0');
        double dMacDet = BigMachinecls.getMachineDetail('tataTek', 'xyz', 5.0, 'test');
    }
}

 Let me know if you have any question.

 

 

developer srideveloper sri

Thanks for the reply!!

 

assertion is failing here.

 

I tried this:

 

system.assertequals(5.0,dMacDet,'dMacDet failure in test');

digamber.prasaddigamber.prasad

Hi,

 

Same is working perfectly fine for me. Could you please check you class, have you made any changes in your methods?

developer srideveloper sri

except assertion is working fine..

 

if you have written assertion, can u pls post it here.

 

Thank you.

digamber.prasaddigamber.prasad

Hi,

 

Below is test class with assertion as said by you:-

 

@isTest
private class BigMachinecls_Test {

    static testmethod void testBigMachinecls() {
        double dU = BigMachinecls.getU('N', 'N', 'N', double.valueOf('5.0'), '10.0');
        double dMacDet = BigMachinecls.getMachineDetail('tataTek', 'xyz', 5.0, 'test');
        system.debug('dU:-->' + dU);
        system.debug('dMacDet:-->' + dMacDet);
        system.assertequals(5.0,dMacDet,'dMacDet failure in test');
    }
}

 Let me know if you still have any issue.

This was selected as the best answer
developer srideveloper sri

Thank you so much for your response.

digamber.prasaddigamber.prasad

Happy that it worked for you! Could you please also give me KUDOS for this, if you think I was able to help you.