You need to sign in to do that
Don't have an account?

How to test this class?
Hello, I want to know how to Test this class? because I'm getting the error of coverage code
public class OTPresupuestoControllers { public List<cOT> cOTList{get;set;} public List<cLdd> cLddList {get; set;} public List<cFac> cFacList {get; set;} public String otId; public String prefacturaId {get; set;} public OTPresupuestoControllers() { } public String getPreFacturaId(){ return prefacturaId; } public void setPreFacturaId(string PreFacturaId) { prefacturaId = PreFacturaId; } public String getOtId(){ return otId; } public void setOtId(string OTId) { otId = OTId; this.cOTList = new List<cOT>(); for(OT__c o : [SELECT Id, Name, Total_1__c,Total_2__c,Total_3__c,Total_4__c,Total_5__c, Nombre_del_Cliente_ppto__c, Total_a_Pagar__c, Archivo__c, Forma_de_Pago__c, Requiere_Sena__c,Nombre_de_la_cuenta__c, Pre_Factura__r.Cuenta__r.Ex_Fiscal__c,Cant_1__c,Cant_2__c,Cant_3__c, Cant_4__c,Cant_5__c,Texto_1_fact__c,Texto_2_fact__c,Texto_3_fact__c, Texto_4_fact__c,Texto_5_fact__c,Texto_largo_1_presup__c, RUC__c,Pre_Factura__r.Tarjeteria__c,Sucursal__c,Firma__c OT__c.Saldo_a_Pagar__c From OT__c Where Id=:otId Limit 1]) {cOTList.add(new cOT(o));} this.cLddList = new List<cLdd>(); for(Linea_de_detalle__c x: [Select Id, Name, Codigo__c, Descripcion_del_Producto__c, Q__c, P_Unit_Linea__c, Total_Linea__c, Grupo_DP__c, createddate From Linea_de_detalle__c Where OT__c=:otId ORDER BY createddate]) {cLddList.add(new cLdd(x));} this.cFacList = new List<cFac>(); for(Factura__c z: [Select Id, Name, Saldo_Final__c From Factura__c Where Pre_Factura__c =:prefacturaId Limit 1]) {cFacList.add(new cFac(z));} } public class cOT{ public OT__c OT{get; set;} public String totalapagar{get;set;} public cOT(OT__c o){ this.OT = o; this.totalapagar= NumberToSpanishWords.convertToGs(o.Total_a_Pagar__c); } } public class cLdd{ public Linea_de_detalle__c LDD {get; set;} public string P_Unit_Linea {get; set;} public string Total_Linea {get; set;} public string Q {get; set;} public cLdd(Linea_de_detalle__c x){ this.LDD = x; this.P_Unit_Linea=NumberToSpanishWords.convertToGs(x.P_Unit_Linea__c); this.Total_Linea=NumberToSpanishWords.convertToGs(x.Total_Linea__c); this.Q=NumberToSpanishWords.convertToEU(x.Q__c); } } public class cFac{ public Factura__c FAC {get; set;} public string saldofinal {get; set;} public cFac(Factura__c z){ this.FAC = z; this.saldofinal=NumberToSpanishWords.convertToGs(z.Saldo_Final__c); } } }
NOTE: This code has not been tested and may contain typographical or logical errors
Take a look over this [1] to learn more about testing strategies
[1] http://blog.deadlypenguin.com/blog/testing/strategies/
All Answers
Each test should follow the following structure:
- Setup of test data. This includes creation of any data needed by your class. Account, Contacts etc
- Starting the test. This is calling Test.startTest() to reset the governor limits
- Calling your class / method
- Stopping the test.This is calling Test.stopTest() to reset the governor limits and allow for any async jobs to finish
- Asserting that your changes have worked
- If you have inserted/updated/deleted data, you need to query for the updates
- Run System.assert, System.assertEquals, System.assertNotEquals to verify that you got the correct data back
If you have any specific problems with your tests, feel free to create a new post with the part of the class you are trying to test and your current test method, and you will more likely get a better response then asking for someone to essentially write an entire test class for you.[1] http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
[2] http://pcon.github.io/presentations/testing/
[3] http://blog.deadlypenguin.com/blog/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/
[4] http://blog.deadlypenguin.com/blog/testing/strategies/
I don't know how to test because I got an error of constructor.
I just need a little example of how to test a constructor or a list
part of my apex, if I get I liitle a example I can then see how to do the others one.
my lillte test
NOTE: This code has not been tested and may contain typographical or logical errors
Take a look over this [1] to learn more about testing strategies
[1] http://blog.deadlypenguin.com/blog/testing/strategies/
thanks pcon