+ Start a Discussion
Mohan SFDC 25Mohan SFDC 25 

need help in test class for code coverage increase

Hi All,

pls help me in code coverage 
This is my controller class
public with sharing class Solution{

    public Boolean displayPopup {get;set;}
    public List<Object__c> Records {get; set;} 
    public User username {get; set;} 
    public string userid {get; set;}
    public String searchTerm {get; set;}
    public String selecteduser {get; set;}
    public String uId {get; set;}
    public List<User> UserTemp = new List<User>();
    // To load data into the table
    public PACV_SolutionsTab_CC(ApexPages.StandardController controller) 
        userid = Userinfo.getUserId();       
        Records =   [SELECT Name,some fields,Owner.name FROM Object__c WHERE CreatedById = :userid]; 
    // User Auto Complete related code
    public String getSearchTerm() 
        return null;
     // For auto complete functionality
        public static List<User> searchuser(String searchTerm) {
       // System.debug('user Name is: '+searchTerm );
        List<User> user = Database.query('SELECT Name,Id FROM User where Name like \'%' + String.escapeSingleQuotes(searchTerm) + '%\' Limit 20');  
        return user;
    // Assigns permission sets to the appropriate users
    // This is run as part of the setup wizard and after installations.       
      public  PageReference AssignPermissionSets()
          PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
          list <PermissionSetAssignment> PSAssignments = new list <PermissionSetAssignment>();
          List<User> users = [SELECT ID,(Select id,AssigneeId FROM PermissionSetAssignments WHERE PermissionSetID = :ps.Id) FROM User WHERE Profile.UserLicense.Name= 'Salesforce Platform' AND IsActive = true AND Id = :selecteduser];
            for( User u : users ){
                if(u.PermissionSetAssignments.size() == 0) 
                PSAssignments.add( new PermissionSetAssignment(AssigneeId = u.id,PermissionSetId = ps.ID ) );
                insert PSAssignments;
              displayPopup = false;
                return null;
    // To show popup and its functionality
    public void showPopup()
        displayPopup = true;    
    public void closePopup() 
        displayPopup = false;        

This is my test class
public class TabNametest
public static testMethod void SolutionTabMethod() {
        Object__c o = new Object__c (Name='Test',Contact_Phone__c='0987654321',Supplier_Phone__c='1234567890');
        insert o;
       Profile p1 = [select id from Profile where name='Standard Platform User']; 

        User opUser = new user(alias = 'test123', email='test123@noemail.com',emailencodingkey='UTF-8', firstName='Pawan', lastname='Testing', 
                               languagelocalekey='en_US',localesidkey='en_US', profileid = p1.Id, country='United States',
                               timezonesidkey='America/Los_Angeles', username='test01@noemail.com'); 
            insert opUser;
            PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
            insert new PermissionSetAssignment(AssigneeId = opUser.id, PermissionSetId = ps.Id );
            PageReference myPage = Page.Solution;
            myPage.getParameters().put('id', o.Id);  
            ApexPages.StandardController control = new ApexPages.Standardcontroller(o);
            Solution pageControl = new Solution(control); 
				pageControl.selecteduser = opUser.id;
			}Catch(Exception ee)	


Not able to cover 28 to 34 lines of code
Hi Mohan,

try performing search processing in your controller class.
add something like this in your test class:
List<User>  users  = Solution.searchuser("search text");

Good Luck!