Thursday 20 February 2014

Test Class in Salesforce

Hi Guys 
This post is only for somebody (who are new to test class in salesforce) who asked me to write a test class for one of my Post 

Unit tests are class methods that verify whether a particular piece of code is working properly. Unit test methods take no arguments, commit no data to the database, send no emails, and are flagged with the testMethod keyword or the isTest annotation in the method definition. Also, test methods must be defined in test classes, that is, classes annotated with isTest.

Here I am sharing some links regarding test class basic functionality. Please go through this.

http://salesforceworld.blogspot.in/2012/03/unit-testing-in-salesforce.html
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm.

Roopal Chouhan ,Here is the example of test class which you had asked me to write for this Controller

Here is the test class. 
/**
 * Testing and Code Coverage.
 */
@isTest
private class TestClass {

    static testMethod void myUnitTest() {
        creatingListOfRecordsController  clsObj = new creatingListOfRecordsController();
        /*Account acct =  new Account();
        acct.Name = 'testAccount';*/
        
        Apexpages.currentpage().getParameters().put('index','1');
      
       clsObj.addRow();
       for(creatingListOfRecordsController.Accountwrapper innnerCls : clsObj.accountwrapperList) {
             innnerCls.account.Name = 'acct';
        }
        
        clsObj.saving();  
        clsObj.removingRow();  
    }
}

2 comments:

Unknown said...

nice post...It is very helpful
good job Asish

Unknown said...

Introduction of cloud servers have created a greatest impact over data interpretation. Also they made a history in cloud computing. Handling data made much easier and more comfortable like never before. Your content tells the same about the emerging technology. Thanks for sharing this information in here.

Salesforce training in chennai | Salesforce training