I having written a lot of code and there are like 25 Function which have no parameter and no Return Type. What is the best way to test the Method?

Below is my code:

public void solenoidPriceUpdate(){
  List<VWC_Solenoid_Dup__c> priceList;
               priceList=[Select Price__c,PreviousPrice__c,Code__c,price_check__c from VWC_Solenoid_Dup__c]; 
                priceList=[Select Price__c,PreviousPrice__c,Code__c,price_check__c from VWC_Solenoid_Dup__c where Code__c=:selectedSolenoids]; 
        for(VWC_Solenoid_Dup__c priceUpdate:priceList){
                                        /////////insert into the PriceLog
               Price_Update_Log__c prices=new Price_Update_Log__c(Object_Name__c=selectedSeries,    
               Price_Field_name__c=priceUpdate.Code__c );
           update priceList;
           insert priceLog;

So this function what mistake did I query inside the function?

  • That should be fine, What I do is write different test method for each flow/scenario by satisfying different data and adding asserts. Try not to include multiple scenarios in single method, otherwise it becomes hard for validation. For better support you should update your question with specific details.
    – Raul
    Mar 13, 2017 at 12:20

1 Answer 1


Testing a method doesn't mean you should have parameters and return types.

Following things you can validate though your test method.

1) Prepare VWC_Solenoid_Dup__c data which contains Code__c specific to selectedSolenoids.

2) Test the execution when selectedSolenoids=='ALL' and the other flow when Code__c = selectedSolenoids

3) Based on the records you have created, you can put assert on priceList to check the size.

4) Assert on Price_Update_Log__c records (on each attribute) which has been updated based on priceUpdate values.

5) Check the size of priceLog.

6) Any other failure conditions and if Price_Update_Log__c contains any validation rules or workflow field update then you can verify that after the insertion.

Hope it helps!

  • @Malik, if my answer solves your purpose then accept this answer so that other members can find this useful Mar 13, 2017 at 13:25
  • @SantanuBoral Thank you, Sir, can you please can just give me a little code for demo from where to start this and it's helping me a lot, the Other thing I don't know where to select your Answer is the correct answer
    – Malik
    Mar 14, 2017 at 5:56
  • @SantanuBoral Sir Its Perfect fine with Referring to 2 Point but when I add data into List it is not working like there is no data into PriceList because the for Loop is not working or not covered into testCase
    – Malik
    Mar 14, 2017 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .