You need to sign in to do that
Don't have an account?
iyappan kandasamy 4
For addition of 2 numbers want to know the test class is correct or not because my code coverage is only 0% .....
Actually this is my apex class for addition of 2 numbers
public class Addition //define class
{
public integer a=5; //define variables
public integer b=4;
public integer c;
public integer add() //define function or method
{
c=a+b;
system.debug('the result is '+c);
return c;
}
}// end of class
My Test class
----------------
@isTest
public class Additiontest
{
static testmethod void testadd()
{
integer a=5;
integer b=7;
integer c=12;
system.assertEquals(12,12);
}
}
and when executing the test class it is showing as pass...
Please need help on this....thanks
public class Addition //define class
{
public integer a=5; //define variables
public integer b=4;
public integer c;
public integer add() //define function or method
{
c=a+b;
system.debug('the result is '+c);
return c;
}
}// end of class
My Test class
----------------
@isTest
public class Additiontest
{
static testmethod void testadd()
{
integer a=5;
integer b=7;
integer c=12;
system.assertEquals(12,12);
}
}
and when executing the test class it is showing as pass...
Please need help on this....thanks
Test class is used to test your functionality(class you have writter), and in order to test your functionality you need to invoke the Addition class and its methods.
In your test class you have just added the two integers. you need to invoke your class as below in your test class
Refer: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
All Answers
Test class is used to test your functionality(class you have writter), and in order to test your functionality you need to invoke the Addition class and its methods.
In your test class you have just added the two integers. you need to invoke your class as below in your test class
Refer: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
one more doubt I have
For fetching custom object records I have written Apex code as:
Apex class for fetching Bank object custom records
-------------------------------------------------------------------
public class RetBank
{
public void retrievedata()
{
banks__c[] bk=[select Id,Name from banks__c];
for(banks__c bnk:bk)
{
system.debug('The records are:'+bnk);
}
}
}
Test class
-------------
@isTest
public class RetBanktest
{
static testmethod void banks()
{
RetBank fb=new RetBank();
fb.retrievedata();
}
}
It is WOrking properly but the test class is giving only 75% ..Y it is not giving 100%....Any guidance please....THanks in advance
Sorry for the delay! May be you have already solved your query, but still here is the answer to your query:
In your apex code you are querying(fetching) banks__c records and then you are iterating over the list of records fetched.
Also, in your test class you have invoked a method of class. But when you code is running under test execution it does not refer any records from your Salesforce Org and you do not get any records in the list you have fetched, So your code will not go inside the for loop to debug your record and hence that part in your test class is uncovered. Your test class would be simulation which would test scenarios.
Now to test your apex code which requires records of object you need to create them in your Test code as below:
Test class
-------------
please refer the Apex Test method guide for reference
Thanks!