I'm trying to test a class. Doing so, I'm changing the objects state, yet for some reason, that change is only temporary.
Here is what I mean:
class ownerTest {
Owner Tom = new Owner(); // creates owner and initializes arraylist of type pet
Pet Doggy = new Pet("Rexy"); // creates pet object doggy
@Test
public void test1() {
Tom.addPet(Doggy); //will add doggy on to tom's arraylist
assertEquals(Doggy, Tom.petList.get(0)); // passes
}
@Test
public void test2() {
assertEquals(Doggy, Tom.petList.get(0)); // fails cause arraylist is empty
}
I've been told that I can treat test classes much like normal classes. Then why are changes made to objects in test units only temporary?
Would love some clarification.
PS: The equals method has been adjusted accordingly so it's not about that.
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire