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
RajevlsRajevls 

Test Class Error

I have written this piece of code in a class to use it in trigger :

 

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

public class ConversionHelper 

static boolean flagvalue = false;


    public static boolean hasAlreadyfired() {
        return flagvalue;
    }
    
    public static void setAlreadyfired() {
        flagvalue = true;
    }

}

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

 

In the test class to cover this part of the code :

 

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

@isTest

private class ConversionHelper_TC {

 

Boolean hasfired = CurrencyConversionHelper.hasAlreadyfired();

 

CurrencyConversionHelper.setAlreadyfired();

 

}

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

Getting the following errors :

 

For  - CurrencyConversionHelper.setAlreadyfired(); - Method must define a body at line 14 column 2

For - Boolean setfired = CurrencyConversionHelper.setAlreadyfired(); - Compile Error: Illegal assignment from void to Boolean at line 14 column 1

 

 

This is not getting covered in the class .

Plz help.

Vinit_KumarVinit_Kumar

You are missing testmethod keyword in your testclass,try below :-

 

public class ConversionHelper 

static boolean flagvalue = false;


    public static boolean hasAlreadyfired() {
        return flagvalue;
    }
    
    public static void setAlreadyfired() {
        flagvalue = true;
    }

 

static testmethod void MyUnitTest(){
Boolean hasfired = CurrencyConversionHelper.hasAlreadyfired();
CurrencyConversionHelper.setAlreadyfired();

}