You need to sign in to do that
Don't have an account?
Klivingston
Test Class
Hi everyone,
Can you please help me to write a test class for below code:
public class retrieveOpenSiteDefects { private ApexPages.StandardSetController controller; public List<Site_Defects__c> getOutbaseSiteDefects() { return [SELECT Id, Name, Date_Raised__c,Contractor__c,Defect_Type__c,Status__c FROM Site_Defects__c WHERE Status__c = 'Open' order by Date_Raised__c desc limit 10]; } }
I have been trying by this:
@isTest public class testRetrieveOpenIncidents{ static testMethod void testOpenIncident(){ Incident__c i = new Incident__c(Name='test',Current_Owner__c= 'me', Date_Occurred__c= 2013-11-12, Description__c= 'none', Due_Date__c= 2013-11-25, Open_Actions__c= 'Investigate,', RCA_Approved__c='Y', RCA_Submission_Date__c= 2013-11-12, Status__c= 'Under Investigation', Terminal__c= 'Test' Transport_Contractor__c= 'salesforce test' ) }
for some reason it does not like date :/
Thanks
I'm not sure if this is the best way to do it (I'm new to Apex and coding in general), but I've found this works: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Date_newInstance.htm
For instance:
will return the 15th of the current month.
Thanks stephaniearceguzman, that did solve the date problem. so complicated compare to other language is itn't ! What I dont understand is how this test class will affect on my apex class because there is no ref to my Apex class? here is what I have now:
Hey Klivingston,
Except triggers , in every test class we need to refer or create an instance of the class. without creating instance you can't have the code coverage for the main class
This post is having the same thing you need to know
http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html
Hi Abhi
can you please help me to complete this test class. I checked your link but I could not figure out how it works. My custom class is called by a VisualForce page. And I wrote this test class as its need %75 code coverage to be pushed to production.
How to create an instance of my custom class in the test class?
Thanks
This is my VF page: