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
JoshTonksJoshTonks 

I need help with writing a Test Class

Im fairly new to apex im only just getting into it.

I have written the following but Im still trying to get my head round writing a test class and would be grateful for any assistance on doing so. Im sure ill eventually get my head round this.
 
public class CaseCon {
    List<case> CaseCon;
        public List<case> getCaseCon() {
            CaseCon = [SELECT Account.Name, Owner.Name, CaseNumber
                       FROM Case
                       WHERE Urgent__c = :TRUE];
            return CaseCon;
        }
}

 
Best Answer chosen by JoshTonks
PawanKumarPawanKumar
Please try below and let me know if it helps you.

----------------------------------------------

@isTest(SeeAllData=false)
private class CaseConTest {

 static testMethod void testCon() {
  
  Case newCase = new Case();
  newCase.Urgent__c = true;
  // please add any other mandatory field 
  insert newCase;
  
  //instance of class
  CaseCon con = new CaseCon();
  List <case >caseList = con.getCaseCon();
   
  // assert 
  System.assertEquals(1, caseList.size());
 }

}

------------------------------------------

Regards,
Pawan Kumar

All Answers

PawanKumarPawanKumar
Please try below and let me know if it helps you.

----------------------------------------------

@isTest(SeeAllData=false)
private class CaseConTest {

 static testMethod void testCon() {
  
  Case newCase = new Case();
  newCase.Urgent__c = true;
  // please add any other mandatory field 
  insert newCase;
  
  //instance of class
  CaseCon con = new CaseCon();
  List <case >caseList = con.getCaseCon();
   
  // assert 
  System.assertEquals(1, caseList.size());
 }

}

------------------------------------------

Regards,
Pawan Kumar
This was selected as the best answer
JoshTonksJoshTonks
Thank you so much that works perfectly. Pawan you are a life saver.