dimanche 28 février 2016

Java J-unit tests

I am testing a class that was implemented from an interface. In my test class, I have created objects (Humains) that have a name and bank account value.

One of my methods to test takes an arrayList and compares with another list and if the person already exists, the amount will be added.

Code is something like that: TEST CLASS

HumainImpl<Humain> humain = new HumainImpl<Humain>();
private Humain h1 = new Humain("AAA" , 2200);
private Humain h2 = new Humain("DDD" , 500);

@Test
public void testAddAmount(){
List<Humain> testing = new ArrayList<Humain>();
testing.add(h1);
testing.add(h2);

humain.placeList(testing);
}

the placeList(testing) method is in the HumainImpl class which calls another method in the Humain class that does the addition. In the HumainImpl class there is also a list called implList. Once this method placeList is called, the numbers for h1 and h2 in the test class are changing. What I want, is that only the number for the implList to change.

Is it something normal that when adding up numbers or making changes while passing the h1 and h2 as parameter they will get effected ?

I have tried too many ways and I don't get it. I tried going through the list passed as a parameter copy the element in that list into another attribut and do the addition but it didn't help.

This works fine when I test another similar method that takes an element as a attribut, place(h1).

Aucun commentaire:

Enregistrer un commentaire