jeudi 28 juillet 2016

How to organise the tests of an expensive object

I have a class A that I want to test with JUnit. Creating of an object of type A involves a lot of IO, so it takes about 5 seconds.

A is mutable and I want to test the different methods that change A. Now I am in some kind of dilemma:

  1. If I create a virgin object A for every test method, it just takes too long.
  2. Creating one huge test method with a lot of asserts seems like a bad idea to isolate the causes of possible errors.
  3. "Repairing" the object of type A after each test methods seems to dangerous as well because if the repairing is not done correctly, other test methods might fail without proper reason.
  4. I could also create a deep copy of an instance of A for every test method, but that means that I have to change the class A only to properly test it.

What would you suggest?

Aucun commentaire:

Enregistrer un commentaire