+ Start a Discussion
iyappan kandasamy 4iyappan 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.
Best Answer chosen by iyappan kandasamy 4
v varaprasadv varaprasad
hi iyappan,

try this : 
 
@istest
public class Addtest
{
static testmethod void testadd()
{

public integer a;
public integer b;
public integer c;

    Add ad=new Add();
	ad.a = 10;
	ad.b = 20;
	
    integer res=ad.addt();
    system.assertEquals(30,res);
}
}

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

Steven NsubugaSteven Nsubuga
make these changes in order for your code to be more meaningful.

Class
public class Add 
{    
    public integer a;
    public integer b;
    public integer c;
    public integer addt(integer a, integer b)
    {
        c=a+b; 
        system.debug('the result is'+c);
        return c;
    }      
}


Test Class
@istest
public class Addtest
{
    static testmethod void testadd()
    {
        Add ad=new Add();
        integer res=ad.addt(2, 5);
        system.assertEquals(res, 7);
    }
}


 
v varaprasadv varaprasad
hi iyappan,

try this : 
 
@istest
public class Addtest
{
static testmethod void testadd()
{

public integer a;
public integer b;
public integer c;

    Add ad=new Add();
	ad.a = 10;
	ad.b = 20;
	
    integer res=ad.addt();
    system.assertEquals(30,res);
}
}

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
This was selected as the best answer
iyappan kandasamy 4iyappan kandasamy 4
Great...Thanks .a lot for both of them...Steven Nsubuga and varaprasad...It worked out for me...