+ Start a Discussion
Sivakumari2iSivakumari2i 

Help - Test Method

Hi,

 

Can anyone help me in writing test method for the following apex controller.

 

public with sharing class LookupPopupController
{
    public String query {get; set;}
    public List<Opportunity> opportunities {get; set;}
    public PageReference runQuery()
    {
        List<List<Opportunity>> searchResults = [FIND :query IN ALL FIELDS RETURNING Opportunity (id, name, StageName, Amount, CloseDate, FiscalQuarter, FiscalYear Where ForecastCategory IN ('Pipeline', 'Best Case') and CloseDate = THIS_FISCAL_QUARTER order by StageName)];
        Opportunities = searchResults[0];
        return null;
    }
}

 

Thank you,

S.Sivakumar

 

ryanjuptonryanjupton

Here's an example of one way to do it. You'll only want to use this as a guide and create a more substantial test.

 

@isTest
public class TestLookupPopupController{
	public static testMethod void testLPC(){
		LookupPopupController controller = new LookupPopupController();
		controller.query = 'myval';
		PageReference pageRef = controller.runQuery();
        System.assert(controller.opportunities.size() > 0);
	}
}

 

Sivakumari2iSivakumari2i

Hey i am new to this, I dont know how to modify the test code.

 

If i run that code i am getting "Assertion failed" as an error message.

 

Please help me to achive the code coverage.

 

Thanks,

S.Sivakumar.

 

Sivakumari2iSivakumari2i

If i remove System.assert line i am getting 100%code coverage.

 

Is that a right way to do?

 

Please correct me.

 

Thanks,

S.Sivakumar.