I've been reading up on Unit testing and I'm trying to get a test done for a class. I want to delpoy this to our live Org but am pretty stuck at this: The Code itself works but I've never done unit testing before so I'm pretty lost I have a Page, a Class and a Test Class. Can some one help me with this?
Page:
<apex:page standardController="Estimate__c"
extensions="EstimateClone"
action="{!cloneRecord}">
<apex:pageMessages />
</apex:page>
Class:
public with sharing class EstimateClone {
//Variable to hold current record
Estimate__c currentRecord;
//Standard constructor method
public EstimateClone (ApexPages.StandardController controller)
{
currentRecord = (Estimate__c)controller.getRecord();
}
public PageReference cloneRecord()
{
//Variable to hold the new record
Estimate__c newRecord;
Savepoint sp = Database.setSavepoint();
try
{
currentRecord = [Select id, name from Estimate__c where id =:currentRecord.id];
newRecord = currentRecord.clone(false);
newRecord.Name = currentRecord.Name + ' Copy';
newRecord.recordtypeid ='012b0000000PkQU';
insert newRecord;
//Copy the related list
List<Estimate_Product_Line_Item__c> EPLL = new List<Estimate_Product_Line_Item__c>();
for( Estimate_Product_Line_Item__c EstPL : [SELECT Name, Root__c, Type__c, Estimate_Product__r.Name,
Quantity__c, Price__c, Comments__c FROM
Estimate_Product_Line_Item__c WHERE
Estimate__c =:currentRecord.id])
{
Estimate_Product_Line_Item__c newEstPL = EstPL.clone(false);
newEstPL.Estimate__c = newRecord.id;
EPLL.add(newEstPL);
}
insert EPLL;
}
catch(Exception e)
{
Database.rollback(sp);
ApexPages.addMessages(e);
return null;
}
return new PageReference('/'+newRecord.id);
}
}
Test Class:
@istest
public class TestClass {
static testMethod void EstimateCloneTest() {
//EstimateClone Test
Estimate__c es = [select Name, Comments__C, Opportunity__c, Status__c
from Estimate__c
where id = 'a0E17000000RrB7'];
PageReference pageRef = Page.EstClone;
pageRef.getParameters().put('Id',es.Id);
Test.setCurrentPage(pageRef);
EstimateClone EC = new EstimateClone(new ApexPages.Standardcontroller(es.id));
EC.CloneRecord();
System.assert(EC.Name == es.Name+' Copy');
}
}