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
David JoshuaDavid Joshua 

How to use System.assertEquals(ANY expected, ANY actual, ANY msg) when I have many results expected ?

Hi, 

I would like to use System.assertEquals(ANY expected, ANY actual, ANY msg) with something like that : 
    @IsTest
    static void testRecoverValue() {

        Integer val1 = 1353;
        Integer val2 = 1300;
        Integer val3 = 0; 

        String json = FranceOperation_Utility_ReloadImpressions.getjsonFranceOperationTargetingDistibution();
        Integer val = FranceOperations_TargetDistri.parse(json);
        System.assertEquals(val1||val2||val3, val, 'test for function recoverValue() suceeded');
    }
I know the syntax on my last line is not correct but I would like to know the proper way to write it. Is there a way to include many integers in my value expected. How do I do that ? Should it be more like this : 
System.assertEquals(val1, val, 'test for function recoverValue() suceeded') || 
System.assertEquals(val2, val, 'test for function recoverValue() suceeded') || 
System.assertEquals(val3, val, 'test for function recoverValue() suceeded');
(I'm a begginer, and moreover, who has not written many tests before. Thank you for your patience !)
 
Best Answer chosen by David Joshua
Raj VakatiRaj Vakati
The only way you can able to do it keep the values in the array and compare
 

 
@IsTest
static void testRecoverValue() {

    Integer val1 = 1353;
    Integer val2 = 1300;
    Integer val3 = 0; 

    String json = FranceOperation_Utility_ReloadImpressions.getjsonFranceOperationTargetingDistibution();
    Integer val = FranceOperations_TargetDistri.parse(json);
List<String> val = new List<String>() ; 
List<String> val1 = new List<String>() ;

    System.assertEquals(val, val1);
}

Or you have to go though the one by by  one as shown below 

 
System.assertEquals(val1, 'test for function recoverValue() suceeded') || 
System.assertEquals(val2, 'test for function recoverValue() suceeded') || 
System.assertEquals(val3, 'test for function recoverValue() suceeded');

 

All Answers

Raj VakatiRaj Vakati
The only way you can able to do it keep the values in the array and compare
 

 
@IsTest
static void testRecoverValue() {

    Integer val1 = 1353;
    Integer val2 = 1300;
    Integer val3 = 0; 

    String json = FranceOperation_Utility_ReloadImpressions.getjsonFranceOperationTargetingDistibution();
    Integer val = FranceOperations_TargetDistri.parse(json);
List<String> val = new List<String>() ; 
List<String> val1 = new List<String>() ;

    System.assertEquals(val, val1);
}

Or you have to go though the one by by  one as shown below 

 
System.assertEquals(val1, 'test for function recoverValue() suceeded') || 
System.assertEquals(val2, 'test for function recoverValue() suceeded') || 
System.assertEquals(val3, 'test for function recoverValue() suceeded');

 
This was selected as the best answer
David JoshuaDavid Joshua
Ok, I see. Thank you @Raj for your quick reply !