This Tutorial will guide you how to test exception in Apex test class

private class TestRestrictContactByName{
    @isTest static void TestVerifyDatemethod() {
       Contact con=new Contact(firstname='Test',lastname='INVALIDNAME');
        Database.SaveResult srList = Database.insert(con, false);
        // Verify
        // In this case the deletion should have been stopped by the trigger,
        // so verify that we got back an error.
       Contact con1=new Contact(firstname='Test',lastname='Valuea');
       insert con1;
       Contact con2=[select lastname from Contact where];
       srList = Database.update(con2, false);