You need to sign in to do that
Don't have an account?
cnewman
Apex Test Class Help
Hi All,
I'm really struggling to get my head around apex test clases. I've build a very basic save controller to help with a function on a small but of VisualForce page. It simply redirects back to the apex page when you save the record.
I just don't know how to build the test class for it. Here's my code:
Thanks
I'm really struggling to get my head around apex test clases. I've build a very basic save controller to help with a function on a small but of VisualForce page. It simply redirects back to the apex page when you save the record.
I just don't know how to build the test class for it. Here's my code:
public with sharing class DemoExtension { ApexPages.StandardController stdCtrl; // extension constructor public DemoExtension(ApexPages.StandardController std) { stdCtrl=std; } public PageReference save() { stdCtrl.save(); PageReference pr=Page.Demo_Q_and_A; pr.setRedirect(false); return pr; } }How do I build a class to test the save function?
Thanks
@istest()
private class TestDemoExtension{
static testMethod void myUnitTestDemoExtension() {
// insert the standard controller record like below
Account acc = new Account();
acc.Name = 'Test'
insert acc;
ApexPAges.StandardController sc = new ApexPages.StandardController(acc);
DemoExtension testExt = new DemoExtension(sc);
testExt.save();
}
}
All Answers
@istest()
private class TestDemoExtension{
static testMethod void myUnitTestDemoExtension() {
// insert the standard controller record like below
Account acc = new Account();
acc.Name = 'Test'
insert acc;
ApexPAges.StandardController sc = new ApexPages.StandardController(acc);
DemoExtension testExt = new DemoExtension(sc);
testExt.save();
}
}
Do I deply test clases differently to live ones?
Chris
Thank you so much for your help!