You need to sign in to do that
Don't have an account?
Gtennent
Test class won't save and can't be selected for a New Run.
I'm trying to complete the "Getting Started with Apex Unit Tests" module on the trailhead. I got to the challenge and created the test class. I did as it says and did an "All Run" then went to complete the challenge, but I got an error back. I checked to see what tests were run and the class I created doesn't show up. I go to "New Run" and it doesn't show up. I saved the class then closed and reopened the tab only to find this:
I retyped my code, saved it (ctrl +c and File > save), copied it, and repeat the steps above. Same thing. When I open the code it comes up blank. Luckily I copied it so I can paste it back in. I closed and reopened the DC window. The tab remembers what I typed, but if I close and reopen it gets wiped. I have logged out and back in; all to no avail. So long story short, what is going on? Why won't my class save anything other than the basic starting info?
Here's a sample of the code. All of the tests repeat the same format so I won't copy them for the sake of brevity.
public class TestVerifyDate{ }
I retyped my code, saved it (ctrl +c and File > save), copied it, and repeat the steps above. Same thing. When I open the code it comes up blank. Luckily I copied it so I can paste it back in. I closed and reopened the DC window. The tab remembers what I typed, but if I close and reopen it gets wiped. I have logged out and back in; all to no avail. So long story short, what is going on? Why won't my class save anything other than the basic starting info?
Here's a sample of the code. All of the tests repeat the same format so I won't copy them for the sake of brevity.
@isTest private class TestVerifyDate { @isTest static void dateTest11(){ Date date11 = VerifyDate.CheckDates(07/18/2016, 07/29/2016); System.assertEquals(07/29/2016, date11); } //Repeat other tests below. All brackets are closed, all semi-colons are present. //This follows the TemeratureConverterTest example test class format shown in the module, //Only changes are variables, methods, etc. }
You need to pass date to the VerifyDate.CheckDates() in your test class.
Thanks
Anupama
All Answers
I would suggest can you go to setup>develop>classes and then create the test class there. Might be a quick fix.
Thanks
Anupama
"Error: Compile Error: Method does not exist or incorrect signature: VerifyDate.CheckDates(Integer, Integer) at line 5 column 23".
Here's the code provided for the challenge. Full code can be found here:https://github.com/developerforce/trailhead-code-samples/blob/master/VerifyDate.cls In the DC when I type VerifyDate. the option comes up as "CheckDates(Date date1, Date date2): Date - verifydate"
What I don't understand is why the "VerifyDate.CheckDates(Integer, Integer)" error has integers when the CheckDates method seems to require dates.
What am I missing?
You need to pass date to the VerifyDate.CheckDates() in your test class.
Thanks
Anupama
Thanks for the help. What is the reason for this: why is that I can put decimals into unit tests but have to use this method for dates?
Thanks,
Geoff
The method is defined with parameters as Dates. you cannot put decimals instead even not in your test class.
Thanks
Anupama
I understand that. Let me clarify. In the same module we have the TemperatureConverter class, which has this code: The test for this uses this code:
My question is, why can I put a number straight into the test when the input is a decimal, but when the input is a date, I have to create another variable to pass a date into the test? In other words why is '70' a valid input for a decimal, but '01/01/2016' isn't a valid input for a date?
Thanks,
Geoff
Ok now I got your question clearly.
Salesforce has primitiive datatypes String, Decimal, Integer, Date, DateTime etc. Please go through the link to read more about them https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_primitives.htm.
The method CheckDates has parameters as Dates and when you give the inut as '01/01/2016' it considers this as a string and not a date. Anything which you give within quotes is consideres as date and in salesforce to pass dates you have to create instance of date class.
Thanks
Anupama