function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Balasubramani DhanapalBalasubramani Dhanapal 

How to write test class following code??


public with sharing class QuoteLineItemsManager{
    Public String qteId;
    Public List<QuoteLineItem> QLIs{get; set;} 
    public void setqteId (String s) {
        qteId= s;
        QLIs=new List<QuoteLineItem>();
        QLIs=[SELECT id,(Select id, PricebookEntry.Name,Description,Quantity,UnitPrice,TotalPrice, Capacity__c from QuoteLineItems ORDER BY SortOrder) from Quote where Id=:qteId].QuoteLineItems;
    Public String getqteId(){
        return qteId;
    Public QuoteLineItemsManager() {                        


Since writing a test class to cover all of the facets of this class is not something that anyone on here will do for you, I can give you some pointers and hopefully get you started.  I would recommend that you do some reading on testing [1] [2] [3] to get a better understanding.  Each of your individual tests should only tests one specific portion of you class (ie a constructor test, sendEmail test, contactSelected test, etc).  You should also have both a postitive (everything works perfectly) and a negative (things are not right) test.

Each test should follow the following structure:
  • Setup of test data. This includes creation of any data needed by your class.  Account, Contacts etc
  • Starting the test. This is calling Test.startTest() to reset the governor limits
  • Calling your class / method
  • Stopping the test.This is calling Test.stopTest() to reset the governor limits and allow for any async jobs to finish
  • Asserting that your changes have worked
    • If you have inserted/updated/deleted data, you need to query for the updates
    • Run System.assert, System.assertEquals, System.assertNotEquals to verify that you got the correct data back
In your case you will be inserting new Quotes and QuoteLineItems, making a new instance of your class and calling your methods directly.

If you have any specific problems with your tests, feel free to create a new post with the part of the class you are trying to test and your current test method, and you will more likely get a better response then asking for someone to essentially write an entire test class for you.

NOTE: Please use the "Add a code sample" button (icon <>) next time to increase readability of your code and make it easier to reference.