You need to sign in to do that
Don't have an account?
How to write test class for both 'If 'and 'Else' statements
hi
i have class like
public class abc
{
integer a,b,c;
public void maths()
{
string s='add';
if(s=='add')
{
c=a+b;
}
else if(s=='sub')
{
c=a-b;
}
}
}
here i want to cover both if and Else blocks.
Please guide me.
Hi,
Please find below code:
All Answers
Hi
You have to make ist condition true for If block then make condition false for else block.
Try this
private static void testmethod() {
string p = 'add'
string p ='sub'
}
Did this post answers your questions...if so please mark it solved..so that others get benifited,
Thanks
asish
Hi,
Please find below code:
I know its too late to rply here of your question.
You can do in efficient way as well.
@isTest public class Testabc
{
static testMethod void testMethod()
{
list<string> methodtype = new list<string>();
methodtype.add('add');
methodtype.add('sub');
for(string type : methodtype){
abc obj = new abc();
obj.a = 5;
obj.b = 5;
obj.s = type;
obj.maths();
System.AssertEquals(obj.c,10);
}
}