
Hey Abhilash , Either change in the save method like below
Note : Use curly braces in if statement as good practicehttps://softwareengineering.stackexchange.com/questions/16528/single-statement-if-block-braces-or-noor if you don't want to change in your main class then try using the belowpublic pagereference save(){
if(!String.isBlank(con.LastName)){
System.debug('LastName------------>'+con.LastName);
insert con;
System.debug('Contact id---------->'+con.id);
}
return new pagereference('/'+con.id);
}
@isTest
public class showContactsController_Test {
public static testMethod void controllerTest(){
Account acc = new Account(Name='Test');
insert acc;
Contact con = new Contact(LastName='Test12',Phone='852149633',AccountId=acc.Id);
insert con;
Pagereference pageRef = Page.showContacts;
pageRef.getParameters().put('LastName','Test123');
pageRef.getParameters().put('id',con.id);
Test.setCurrentPage(pageRef);
Test.startTest();
showContactsController controller = new showContactsController();
PageReference pr1 = controller.doSubmit();
controller.con.LastName = 'TestLName';
Pagereference pr2 = controller.save();
Test.stopTest();
System.assertEquals(pr2.getUrl(),'/'+con.Id);
}
}