You need to sign in to do that
Don't have an account?
David Rodríguez Rincón
No Code Coverage on Trailhead challenges
Hi
I'm going through the Developer Begin Trail, but I'm facing some issues to get the Developer Console to show up the right code coverage (Winter '16).
I tried many of the suggestions out there like uncheck the "Test/Always test run async", uncheck the "Store Only Aggregated Code Coverage", run from the BUILD section... nothing seems to work (and I'm pretty sure I'm covering at least some lines of code...)
The Class I'm testing is the one provided by Salesforce guys:
No matter what I do, the Code Coverage is always 0% (the code coverage for the test classes in the examples, copy and pasting.... is also 0%)
Anyone giving me some help on this?
Thanks!!
I'm going through the Developer Begin Trail, but I'm facing some issues to get the Developer Console to show up the right code coverage (Winter '16).
I tried many of the suggestions out there like uncheck the "Test/Always test run async", uncheck the "Store Only Aggregated Code Coverage", run from the BUILD section... nothing seems to work (and I'm pretty sure I'm covering at least some lines of code...)
The Class I'm testing is the one provided by Salesforce guys:
public class VerifyDate { //method to handle potential checks against two dates public static Date CheckDates(Date date1, Date date2) { //if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month if(DateWithin30Days(date1,date2)) { return date2; } else { return SetEndOfMonthDate(date1); } } //method to check if date2 is within the next 30 days of date1 private static Boolean DateWithin30Days(Date date1, Date date2) { //check for date2 being in the past if( date2 < date1) { return false; } //check that date2 is within (>=) 30 days of date1 Date date30Days = date1.addDays(30); //create a date 30 days away from date1 if( date2 >= date30Days ) { return false; } else { return true; } } //method to return the end of the month of a given date private static Date SetEndOfMonthDate(Date date1) { Integer totalDays = Date.daysInMonth(date1.year(), date1.month()); Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays); return lastDay; } }and my Test Class looks as follow:
@isTest private class TestVerifyDate { @isTest static void checkDatesWithin30Days(){ Date dt1 = date.today(); Date dt2 = dt1.addDays(15); Date dte = VerifyDate.CheckDates(dt1, dt2); System.assertEquals(dt2, dte); } @isTest static void checkDatesDate2BeforeDate1(){ Date dt1 = date.today(); Date dt2 = dt1.addDays(-15); Date dte = VerifyDate.CheckDates(dt1, dt2); //Get the last day of dt1 month Integer totalDays = Date.daysInMonth(dt2.year(), dt2.month()); Date lastDay = Date.newInstance(dt2.year(), dt2.month(), totalDays); Date assertDate = lastDay; System.assertEquals(assertDate, dte); } @isTest static void checkDatesNotWithin30Days(){ Date dt1 = date.today(); Date dt2 = dt1.addDays(45); Date dte = VerifyDate.CheckDates(dt1, dt2); //Get the last day of dt1 month Integer totalDays = Date.daysInMonth(dt1.year(), dt1.month()); Date lastDay = Date.newInstance(dt1.year(), dt1.month(), totalDays); Date assertDate = lastDay; System.assertEquals(assertDate, dte); } }
No matter what I do, the Code Coverage is always 0% (the code coverage for the test classes in the examples, copy and pasting.... is also 0%)
Anyone giving me some help on this?
Thanks!!
First off - great post. Very clear and thank you!
So, to the question at hand - I copied and pasted your code into my dev org and was able to reproduce what you're seeing. Running the test with MavensMate, I confirm that you have 100% test coverage (again, awesome stuff man!)
What I did to get Developer Console to show the coverage:
(P.S. - don't mind the "TestVerifyDateNew" class name, I already had a class with your name in my org)
All Answers
First off - great post. Very clear and thank you!
So, to the question at hand - I copied and pasted your code into my dev org and was able to reproduce what you're seeing. Running the test with MavensMate, I confirm that you have 100% test coverage (again, awesome stuff man!)
What I did to get Developer Console to show the coverage:
(P.S. - don't mind the "TestVerifyDateNew" class name, I already had a class with your name in my org)
and following those steps in that order (I did it before, but not in that exact order) WORKED! Now I can get my Trailhead badge!!
Thanks buddy! I owe you one!
Regards.