+ 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