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

help with code coverage please
I am having a VF page and class and test class.I am getting 43% code coverage.How can i increae it?
Below is my aoex class which gets value from user on VF page and creates account.
When i debug the test classs,i am not getting account.name value even though i gave a.name='testaccount' in my test class.
So i am able to cover those lines of code.Please help me what am i missing.
and this is my test class:
Below is my aoex class which gets value from user on VF page and creates account.
When i debug the test classs,i am not getting account.name value even though i gave a.name='testaccount' in my test class.
So i am able to cover those lines of code.Please help me what am i missing.
public class new_classforpage { Public customobjectt__c pr{get;set;} Public string accountname{get;set;} public string contactname{get;set;} public string contactemail{get;set;} public Account account {get;set;} public new_classforpage(ApexPages.StandardController sc) { pr= (object__c )sc.getRecord(); account=new account(); } Public pagereference save(){ upsert pr; if(accountname!= '' && accountname!= null){ account.name=accountname; upsert account; contact c=new contact(); c.accountid=account.id; c.lastName=contactname; c.Email=contactemail;; insert c; pr.account_Name__c=account.id; update Pr; } return new PageReference('/'+pr.Id+'/e?retURL=%2F'+pr.Id); } }
and this is my test class:
@istest Public class test_classforpage{ static testMethod void test(){ test.startTest(); PageReference pref = Page.mypage; Test.setCurrentPage(pref); Account a =new account(); a.name='accountname'; if(a.name!= '' && a.name!= null){ upsert a; contact c=new contact(); c.lastname='test contact'; c.accountid=a.id; c.email='testemail@gmail.com'; insert c; Purchase_request__c pr =new Purchase_request__c(); pr.account_Name__c=a.id; insert pr; update pr; // Instantiate standard Controller ApexPages.StandardController sc = new ApexPages.StandardController(pr); // Instantiate controller extension myclass mc = new myclass (sc); mc.save(); test.stopTest(); } } }
but you didn't set a value to new_classforpage.accountname.
try adding this to your test class (or perhaps in the new_classforpage)
All Answers
but you didn't set a value to new_classforpage.accountname.
try adding this to your test class (or perhaps in the new_classforpage)