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
Streepie24Streepie24 

Testmethod for else-if constructions

if(a==1){ ... } else if(a==2){ ... } else if(a==3){ ... }

 

 

 

How to test such a construction in a testmethod ?

Message Edited by Streepie24 on 09-18-2009 06:36 AM
Message Edited by Streepie24 on 09-18-2009 06:37 AM
lvivaninlvivanin

we need to test each case individually to get 100% code coverage.

 

For example if we have method calculateA(Integer a) in a class SampleClass. And the method has a logic like:

if(a==1){

...

}

else if(a==2){

...

}
else if(a==3){

...

 



In the TestMethod we should have like:

 

SampleClass sc = new SampleClass();
sc.calculateA(1);
sc.calculateA(2);
sc.calculateA(3);
.....

 hope it helps