You need to sign in to do that
Don't have an account?
BRupholdt
I piece this test together from what I've found but it seems not to do anything toward my unit testing requirements. At least it doesn't error like everything else I've tried to do :/
Beginner's Unit Testing
After searching the forums and reading many of the resources posted, I still don't understand.
I've made a very simple VF page with controller that needs unit testing so I can publish it to my production org. I've started extreme basic so that I can understand the entire process. Try as I might, I don't understand how to make the unit tests for these. I learn best by seeing it done but the examples I find are far more complex than I can wrap my head around just yet. Would someone be willing to write unit tests for these two items so that I have a working example to go forward with? I would greatly appreciate it.
Code:
public String getLongDate() { Datetime cDT = System.now(); return cDT.format('EEEE, MMMM d, yyyy'); } public Goals__c[] getGoals() { return [ Select Completion_Date__c, CreatedById, CreatedBy.Alias, CreatedBy.Id, CreatedDate, Goal__c, Id, IsDeleted, Name, OwnerId, Status__c, Target_Date__c, Timeliness__c from Goals__c where Completion_Date__c = null order by Target_Date__c desc ]; }
I piece this test together from what I've found but it seems not to do anything toward my unit testing requirements. At least it doesn't error like everything else I've tried to do :/
Code:
static testMethod void myTest() { Goals__c g = new Goals__c(Goal__c='test'); insert g; g = [Select Goal__c from Goals__c where Id = :g.Id]; System.assertEquals( 'test', g.Goal__c ); }
But to get started, the test method needs to at least test that the controller class works, so you need to call getGoals()..
public static testMethod void myTest() {
// Not sure what the controller class is called, but if we assume it is called myTest
myTest myTest = new myTest();
myTest.getGoals();
// you should then do an assert to check that the correct number of results are being returned etc...
}