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

Test Class. Help me
I 'm writing this class with its test class and I can save my code because there aren't errors but test class don't cover code of the class.
Can we help me to solve problems?
Thank you.
This is Class :
public class Ordine_Aziendale {
public Quote preventivo{get; set;}
public List<Account> account{get; set;}
public Opportunity opportunita{get; set;}
public List<QuoteLineItem> qtl{get; set;}
public Integer cont{get;set;}
public User utente{get; set;}
public Ordine_Aziendale(ApexPages.StandardController stdcontroller) {
this.preventivo = (Quote)stdController.getRecord();
// Product2 p2 = new Product2 (name='test');
// insert p2;
qtl = [SELECT id , product2.id, product2.name, product2.ProductCode, Quantity, UnitPrice FROM QuoteLineItem WHERE Quote.id =: preventivo.id];
cont = qtl.size();
// account = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.id];
// opportunita = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.AccountId];
}
}
This is my test class :
@isTest
public class Ordine_Aziendale_Test {
static testMethod void Costruttore_Test()
{
/************************* START TEST *************************************/
test.startTest();
List<Account> l_acc = new List<Account>();
Account acc = new Account(name='Test Account', billingStreet='Test', billingCity='Test', billingState='Test', billingCountry='Test');
insert acc;
l_acc.add(acc);
List<Opportunity> l_opp = new List<Opportunity>();
Opportunity opp = new Opportunity();
opp.Accountid = acc.id;
opp.Name = 'test';
opp.StageName = 'Prospecting';
opp.CloseDate = date.today();
opp.Type = 'New Client';
opp.NextStep = 'Test';
opp.LeadSource = 'Business Development';
insert opp;
l_opp.add(opp);
List<Quote> l_preventivi = new List<Quote>();
Quote preventivo = new Quote(Name = 'Test',OpportunityId = opp.id, N_Offerta__c = 'test');
insert preventivo;
l_preventivi.add(preventivo);
// Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
insert pb;
Product2 prod = new Product2(Name = 'Anti-infectives 2007', Family = 'Best Practices', IsActive = true);
insert prod;
List<QuoteLineItem> l_qtl = new List<QuoteLineItem>();
QuoteLineItem qtl = new quotelineitem(quoteid = preventivo.id,quantity = 1,unitprice = 1);
insert qtl;
l_qtl.add(qtl);
ApexPages.StandardController controller = new ApexPages.StandardController(preventivo);
Ordine_Aziendale stdController = new Ordine_Aziendale(controller);
/********************************************** FINISH TEST *************************************/
test.stopTest();
}
}
Can we help me to solve problems?
Thank you.
This is Class :
public class Ordine_Aziendale {
public Quote preventivo{get; set;}
public List<Account> account{get; set;}
public Opportunity opportunita{get; set;}
public List<QuoteLineItem> qtl{get; set;}
public Integer cont{get;set;}
public User utente{get; set;}
public Ordine_Aziendale(ApexPages.StandardController stdcontroller) {
this.preventivo = (Quote)stdController.getRecord();
// Product2 p2 = new Product2 (name='test');
// insert p2;
qtl = [SELECT id , product2.id, product2.name, product2.ProductCode, Quantity, UnitPrice FROM QuoteLineItem WHERE Quote.id =: preventivo.id];
cont = qtl.size();
// account = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.id];
// opportunita = [SELECT id,Name,BillingAddress,ShippingAddress FROM Account WHERE id =: preventivo.AccountId];
}
}
This is my test class :
@isTest
public class Ordine_Aziendale_Test {
static testMethod void Costruttore_Test()
{
/************************* START TEST *************************************/
test.startTest();
List<Account> l_acc = new List<Account>();
Account acc = new Account(name='Test Account', billingStreet='Test', billingCity='Test', billingState='Test', billingCountry='Test');
insert acc;
l_acc.add(acc);
List<Opportunity> l_opp = new List<Opportunity>();
Opportunity opp = new Opportunity();
opp.Accountid = acc.id;
opp.Name = 'test';
opp.StageName = 'Prospecting';
opp.CloseDate = date.today();
opp.Type = 'New Client';
opp.NextStep = 'Test';
opp.LeadSource = 'Business Development';
insert opp;
l_opp.add(opp);
List<Quote> l_preventivi = new List<Quote>();
Quote preventivo = new Quote(Name = 'Test',OpportunityId = opp.id, N_Offerta__c = 'test');
insert preventivo;
l_preventivi.add(preventivo);
// Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
insert pb;
Product2 prod = new Product2(Name = 'Anti-infectives 2007', Family = 'Best Practices', IsActive = true);
insert prod;
List<QuoteLineItem> l_qtl = new List<QuoteLineItem>();
QuoteLineItem qtl = new quotelineitem(quoteid = preventivo.id,quantity = 1,unitprice = 1);
insert qtl;
l_qtl.add(qtl);
ApexPages.StandardController controller = new ApexPages.StandardController(preventivo);
Ordine_Aziendale stdController = new Ordine_Aziendale(controller);
/********************************************** FINISH TEST *************************************/
test.stopTest();
}
}
Just add "N_Offerta__c = 'test' " in my code rest all works like a charm
Code covergae - 100%
Please let me if error arises .
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
I have 0% of code coverage.....
Reposting the answer from ***Jen Bennett.****
Ran into this same issue and found this solution (http://salesforce.stackexchange.com/questions/24082/code-coverage-on-dev-console) that worked for me...
Goto setup -> Develop -> Apex Test Execution and click the Options button.
Make sure "Store Only Aggregated Code Coverage" is UNCHECKED
That fixed the issue for me.
Else please check this page as it contains of all the issues related to your problem ..
https://developer.salesforce.com/forums/?id=906F0000000947WIAQ
Thanks
Paarth Jolly