You need to sign in to do that
Don't have an account?
ASHISH RAI 103
Can anyone explain me what below three test methods are doing?
@isTest public class TestVerifyDate { @isTest static void testOldDate(){ Date dateTest = VerifyDate.CheckDates(date.today(), date.today().addDays(-1)); System.assertEquals(date.newInstance(2016, 4, 30), dateTest); } @isTest static void testLessThan30Days(){ Date dateTest = VerifyDate.CheckDates(date.today(), date.today().addDays(20)); System.assertEquals(date.today().addDays(20), dateTest); } @isTest static void testMoreThan30Days(){ Date dateTest = VerifyDate.CheckDates(date.today(), date.today().addDays(31)); System.assertEquals(date.newInstance(2016, 4, 30), dateTest); } }
These methods are unit tests for verifyDate class.Unit tests methods are class methods that verify whether a particular piece of code is working properly or not.
These methods are testing checkDates method with different inputs.
Assert statements are used to compare the output with the expected value.
System.assertEquals() method, which takes two parameters: the first is the expected value, and the second is the actual value.If the expected value and the actual value are same then assertion passes else it assertion fails. Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
All Answers
These methods are unit tests for verifyDate class.Unit tests methods are class methods that verify whether a particular piece of code is working properly or not.
These methods are testing checkDates method with different inputs.
Assert statements are used to compare the output with the expected value.
System.assertEquals() method, which takes two parameters: the first is the expected value, and the second is the actual value.If the expected value and the actual value are same then assertion passes else it assertion fails. Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
1)Date dateTest = VerifyDate.CheckDates(date.today(), date.today().addDays(20));
The output of this method depends on the logic written in verifyDate class checkDates method.
In your org there will be a class with name verifyDate and it contains a method with name as Checkdates.Here the test class method testOldDate is invoking the checkdates method of verifyDate class to verifythat Checkdates is working properly or not.
2)System.assertEquals(date.today().addDays(20), dateTest);
After invoking the method we should write assert statements to check if the output of the method we are testing and the expected output matches or not.Assert fails if it doesn't match ,this indicates that your logic is not working as expected.
Test classes are not meant for output.They are written to check if the code is working properly and doesn’t break in any situation in Production.
In salesforce inorder to deploy code to production it must have Minimum 75% code coverage.So we have to write test classes for every apex class and trigger in salesforce.
Please refer below links which might help you further.
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_unit_tests.htm
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards