You need to sign in to do that
Don't have an account?
iyappan kandasamy 4
test class for addition of two numbers
Hi,
I have written the apex class for addition of two numbers. but for writing the test class i have issue.
Program is
--------------
public class Add
{
public integer a;
public integer b;
public integer c;
public integer addt()
{
c=a+b;
system.debug('the result is'+c);
return c;
}
}
My test class
-----------------
@istest
public class Addtest
{
static testmethod void testadd()
{
Add ad=new Add();
integer res=ad.addt();
system.assertEquals(res);
}
}
the test class is throwing error as
"Method does not exist or incorrect signature: void assertEquals(Integer) from the type System"
Any guidance please
Thanks in advance.
I have written the apex class for addition of two numbers. but for writing the test class i have issue.
Program is
--------------
public class Add
{
public integer a;
public integer b;
public integer c;
public integer addt()
{
c=a+b;
system.debug('the result is'+c);
return c;
}
}
My test class
-----------------
@istest
public class Addtest
{
static testmethod void testadd()
{
Add ad=new Add();
integer res=ad.addt();
system.assertEquals(res);
}
}
the test class is throwing error as
"Method does not exist or incorrect signature: void assertEquals(Integer) from the type System"
Any guidance please
Thanks in advance.
try this :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Salesforce Project Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
All Answers
Class
Test Class
try this :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Salesforce Project Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
public class SampleTest {
@isTest
static void Summary() {
Sample s = new Sample();
s.xvalue= 5;
s.yvalue = 4;
s.add();
s.div();
s.mul();
s.sub();
}
}
Apex class
public class Sample {
public Integer xvalue {get;set;}
public Integer yvalue {get;set;}
public Integer result {get;set;}
public string operation {get;set;}
public Integer sub() {
result = xvalue-yvalue;
operation = 'Subtraction';
return null;
}
public Integer add() {
result = xvalue+yvalue;
operation = 'Addition';
return null;
}
public Integer mul() {
result = xvalue*yvalue;
operation = 'Multiplication';
return null;
}
public Integer div() {
result = xvalue/yvalue;
operation = 'Divison';
return null;
}
}
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.