An Apex test class is used to confirm if instructions and methods in an application or program are working correctly as desired. Tests can be written for many classes.
Since Salesforce require at least 75% of the code to be tested before it can be deployed to the organization. There are different test classes run to achieve the 75% minimum requirement tests on task codes.
To create an Apex class: [Setup]-[Develop]-[Apex Classes]-[New].
It can also be create through develop console, [You username]-[Develop console]-[File]-[New]-[Apex Class]
Basic strunction of test class
@isTest
public class BaseTest {
// Test Method
public static testmethod void Test1(){
// Prepara data for test
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 200; i++){
Account a = new Account(Name = 'Test ' + i);
accounts.add(a);
}
Test.startTest();
// Put test target here
insert accounts;
Test.stopTest();
}
}