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
Alena Semenova 14Alena Semenova 14 

Hello! Tell me how to write a test for this method? Thank you!

testItemList = [SELECT Id, Right__c, Percent_correct_answers__c FROM Session__c WHERE Id =:SessionId];
        //update field Answer for Session
        if (newItem[0].Answer__c == answer) {
            answerCount++;
            testItemList[0].Right__c=answerCount;
            update testItemList;
            
        }

 
Balu_SFDCBalu_SFDC
Hi,
Try below code sample test class

@isTest
public class yourClass_Test {
  @TestSetup
static void setupdata() {
//first insert one Session__c  record
Session__c  sc= new Session__c (name=''.........);
insert sc;
}
static testMethod void testcase() {
//Query the Session__c record 
Session__c  screc = [SELECT Id from Session__c  LIMIT 1];
   //call your class here and pass screc.Id
-----
---
}
}

hope this helps your porblem.
Raj VakatiRaj Vakati
try tis
 
@isTest
public class yourClass_Test {
  @TestSetup
static void setupdata() {
//first insert one Session__c  record
Session__c  sc= new Session__c (name=''.........);
sc.Right__c='';
sc.Percent_correct_answers__c ='';
//add other fields 
insert sc;


//
}

}