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

code coverage for custom controller class
Hi,
I am rooky in Salesforce. I did not understand very well how I must write a test method for code coverage, but two my first trigger is ok. I can not imagine how to write code coverage for this my controller class
Thanks a lot
Benny
I am rooky in Salesforce. I did not understand very well how I must write a test method for code coverage, but two my first trigger is ok. I can not imagine how to write code coverage for this my controller class
public with sharing class FatturaStampaController { public FatturaStampaController(ApexPages.StandardController controller) { righe= [SELECT Id, Descrizione_Prodotto__c, Prezzo__c, Importo_Riga__c, Quantit__c, Prodotto__c, Iva__c, Importo_Iva__c, Imponibile_Riga__c FROM Riga_Fattura__c WHERE Fattura__c = :controller.getId()]; } public List<Riga_Fattura__c>righe{get;set;} }Can you help me?
Thanks a lot
Benny
Once you've setup a test class, you'll want to add some unit tests. Unit test methods are defined like this:
Inside your test method, you'll want to do a few things.
-
Create some test data - Everything you need to run the test.
-
Call the method test.startTest();
-
Execute whatever action will exercise the code.
-
Call the method test.stopTest();
In general you want to repeat this patter a few times. Specifically, you want to test the following things:-
That, given proper inputs and a proper execution context that all works as expected.
-
That, given *im*proper inputs and a proper execution context that the *error* you *expect* to occur has, in fact, occurred.
-
That it works as expected with 1 record.
-
That it works as expected with 213 records.
-
That it fails as expected with 213 records if they contain invalid data.
-
That it works as expected with multiple profiles and users.
these unit tests will, in general demonstrate that the code is properly bulkified, that it is properly safeguarded for security and that you've written the branching logic to properly trap errors that are likely to occur. Here's a set of unit tests that you could write:Create test data for standard object in Testclass like this,
@isTest
public class FatturaStampaTest{
public static void TestMethod Fatturatest(){
Account acc=new Account();
acc.Name='test account';
insert acc;
create test data for your custom object,
Riga_Fattura__c righe=new Riga_Fattura__c();
//Give Required fields here
righe.Fattura__c=acc.Id; // Pass standard object id
insert righe;
ApexPages.StandardController sc = new ApexPages.standardController(acc);
FatturaStampaController fattura=new FatturaStampaController(sc);
}
}
Try this......
thanks a lot KevinP for your explanation and a thanks a Shabbir Shaik for example class. I Try it and tell the result.