You need to sign in to do that
Don't have an account?
siva krishna 61
How to get 100% code coverage for below code
Apex Class
-------------------
public class Calci {
integer a;
integer b;
public void cal()
{
a=10;
b=45;
integer r;
if(a>b)
{
r=a+b;
system.debug('if a greter than b values should be added'+r);
}
else if(a<b)
{
r = a-b;
system.debug('if a is lesser than b values should be subtract'+r);
}
else
{
system.debug('values are equal');
}
}
}
Test Class
--------------
@isTest
public class CalciTest {
public static testmethod void test(){
Calci c = new Calci();
c.cal();
}
}
-------------------
public class Calci {
integer a;
integer b;
public void cal()
{
a=10;
b=45;
integer r;
if(a>b)
{
r=a+b;
system.debug('if a greter than b values should be added'+r);
}
else if(a<b)
{
r = a-b;
system.debug('if a is lesser than b values should be subtract'+r);
}
else
{
system.debug('values are equal');
}
}
}
Test Class
--------------
@isTest
public class CalciTest {
public static testmethod void test(){
Calci c = new Calci();
c.cal();
}
}
you can't cover this class 100% because you are assigning values for a and b in your method.it will cover either a>b or a<b
So don't need to assign values in method.just leave it blank and make interger a ,b as public and assign values diffent values when you are calling your method for different if condition a>b(like a=40,b=10) and a<b(a=10,b=40) in your test class.
I am Adding updated code ,you can uder eaisly.
Class
Test Class:
out put Coverage:
If Information in informative then make my answer as best answer.
All Answers
you can't cover this class 100% because you are assigning values for a and b in your method.it will cover either a>b or a<b
So don't need to assign values in method.just leave it blank and make interger a ,b as public and assign values diffent values when you are calling your method for different if condition a>b(like a=40,b=10) and a<b(a=10,b=40) in your test class.
I am Adding updated code ,you can uder eaisly.
Class
Test Class:
out put Coverage:
If Information in informative then make my answer as best answer.
Apex Code
Unit Test
Feel free to ask if you have any more doubts.
I hope this Code will help you to write test class
Note:-
Apex Code:
Test Class:
Here is the desired output:-
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
Regards,
Akshay
Thanks ,you have any problem ask to feel free ,i will try to solve you problem.(spnvarun0121@gmail.com)