mercredi 9 septembre 2020

How would you create a test for a Constructor?

I'm creating tests for an already complied program, and I'm having trouble getting 100% coverage.

The constructor for a class is:

public Contact(String name, String email){
     if (name == null){
           throw new IllegalAgrugmentException("name must not be null");
     }
}

The test I created reads:

public void testForContactConstructor(){
        Contact testContact = new Contact(null, null);
        assertThrows(IllegalArgumentException.class, () -> {
            testContact.getName();
        });
    }

The test doesn't get covered in eclispe. How would I fix this?

Aucun commentaire:

Enregistrer un commentaire