I am having 2 issues with my Test Class.
Coverage of 3 lines which I have comented on in the code below.
And the insert is failing saying that the account a.id is null.
The controller is used in a Visualforce page.
Do I need to create another test Account in the Save?
public with sharing class MerchandisingController {
public Merchandising__c merch{get;set;}
public string message {get;set;} <u><b> ----no coverage</b></u>
public MerchandisingController (ApexPages.StandardController controller)
{
merch = new Merchandising__c();
merch.Account__c= ApexPages.CurrentPage().getparameters().get('someId');
}
public void save() {
insert merch;
message = 'Record Created Successfully.Please add pictures of the disply to the Account. Thank you!'; ----no coverage
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,message )); ----no coverage
}
}
Test Class
@isTest
private class TestMerchandiseController {
static testmethod void testM(){
Test.StartTest();
Account a = new Account();
a.Name = 'Test Account';
insert a;
ApexPages.StandardController sc = new ApexPages.StandardController(a);
MerchandisingController testMerch = new MerchandisingController (sc);
PageReference pageRef = Page.Merchandising_V2;
pageRef.getParameters().put('id',a.Id);
Test.setCurrentPage(pageRef);
testMerch.save();
Merchandising__c m = new Merchandising__c();
m.Account__c= a.Id;
m.Merchandise__c= 'Trex Rod Rail Display';
m.Merchandise_Category__c= 'Full Size(6ft)';
m.Merchandise_SubCategory__c = 'Black/Black';
insert m ;
System.assert(ApexPages.hasMessages(ApexPages.SEVERITY.CONFIRM));
Test.StopTest();
}
}