function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anton | De OndernemerAnton | De Ondernemer 

Testing Apex Triggers

So I want to write better test classes and started doing the trailhead. I've just completed the following trailhead step:
https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/apex_testing/units/apex_testing_triggers

Somehow I successfully completed the step with the testclass below.
Both "block"-methods keep failing when running all tests. It fails because of the error thrown, but isnt that exactly what I'm testing for so the tests should pass? (I expect an error and I got it).

TLDR: 
is a failed test "good" when testing errors or should I write my test methods differently so it passes?
@isTest
private class TestRestrictContactByName {

    @isTest static void allowContactInsert() {
        Contact contact = new Contact(LastName='LastName');
                
        Test.startTest();
        Database.UpsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(result.isSuccess());
    }
    
    @isTest static void blockContactInsert() {
        Contact contact = new Contact(LastName='INVALIDNAME');
        
        Test.startTest();
        Database.UpsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name '+contact.LastName+' is not allowed for DML',
                             result.getErrors()[0].getMessage());
     }
    
    @isTest static void allowContactUpdate() {
        Contact contact = new Contact(LastName='LastName');
        insert contact;
        contact.LastName = 'AdjustedLastName';
        
        Test.startTest();
        Database.upsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(result.isSuccess());
    }
    
    @isTest static void blockContactUpdate() {
        Contact contact = new Contact(LastName='LastName');
        insert contact;
        contact.LastName = 'INVALIDNAME';
        
        Test.startTest();
        Database.UpsertResult result = Database.upsert(contact);
        Test.stopTest();
        
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name '+contact.LastName+' is not allowed for DML',
                             result.getErrors()[0].getMessage());
    }

}