Create a unit test for a simple Apex class

Install a simple Apex class, write unit tests that achieve 100% code coverage for the class, and run your Apex tests.
  • The Apex class to test is called 'VerifyDate', and the code is available here. Copy and paste this class into your Developer Edition via the Developer Console.
  • 'VerifyDate' is a class which tests if a date is within a proper range, and if not will return a date that occurs at the end of the month within the range.
  • The unit tests must be in a separate test class called 'TestVerifyDate'.
  • The unit tests must cover scenarios for all lines of code included in the Apex class, resulting in 100% code coverage.
  • Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.

 

Create a unit test for a simple Apex trigger

Install a simple Apex trigger, write unit tests that achieves 100% code coverage for the trigger, and run your Apex tests.
  • The Apex trigger to test is called 'RestrictContactByName', and the code is available here. Copy and paste this trigger into your Developer Edition via the Developer Console.
  • 'RestrictContactByName' is a trigger which blocks inserts and updates to any contact with a last name of 'INVALIDNAME'.
  • The unit tests must be in a separate Apex class called 'TestRestrictContactByName'.
  • The unit tests must cover scenarios for all lines of code included in the Apex trigger, resulting in 100% code coverage.
  • Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.

Create a contact test factory

Create an Apex class that returns a list of contacts based on two incoming parameters: one for the number of contacts to generate, and the other for the last name. The list should NOT be inserted into the system, only returned. The first name should be dynamically generated and should be unique for each contact record in the list.
  • The Apex class must be called 'RandomContactFactory' and be in the public scope.
  • The Apex class should NOT use the @isTest annotation.
  • The Apex class must have a public static method called 'generateRandomContacts' (without the @testMethod annotation).
  • The 'generateRandomContacts' method must accept an integer as the first parameter, and a string as the second. The first parameter controls the number of contacts being generated, the second is the last name of the contacts generated.
  • The 'generateRandomContacts' method should have a return type of List<Contact>.
  • The 'generateRandomContacts' method must be capable of consistently generating contacts with unique first names.
  • For example, the 'generateRandomContacts' might return first names based on iterated number (i.e. 'Test 1','Test 2').
  • The 'generateRandomContacts' method should not insert the contact records into the database.