dimanche 7 mars 2021

What is the correct way to test classes in Python?

There is a class named State that has several attributes, which I need to write unit tests for. The test will need to have certain actions that change attribute values of the State instance. Expected parameters are located inside of the dictionary. The unit test will compare the attributes of the State instance with the values of the dictionary for equality.

The question is what is the best place to keep the comparison logic at? I was thinking about 2 options:

  1. Add __eq__ method to the State class that contains comparison logic.
  2. Add helper function inside of the test module that contains comparison logic.

Which one of the options is better and why?

Aucun commentaire:

Enregistrer un commentaire