mardi 9 janvier 2018

Is this a valid way for testing a constructor

I recently started OOP (in Java) and was wondering if the following piece of code could validate if the constructor has been tested well, using a Junit test:

@Test
public void testConstructor() {
    myClass c1 = new myClass("Text", 1);
    myClass c2 = new myClass("Text", 1);
    assertEquals(c1,c2);
}

@Test
public void testConstructor2() {
    myClass c1 = new myClass("Text", 1);
    myClass c2 = new myClass("Text", 2);
    assertNotEquals(c1,c2);
}

Although it seems to be a valid check to me, I'm still a bit confused because most examples I've found about constructor testing use a .get() method.

Any clarification would be appreciated!

Aucun commentaire:

Enregistrer un commentaire