Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3 Antwoorden
10023 Weergaven

When testing a model (models.Model), we use the ORM to create instances of the model and make assertions about its behavior. Since an abstract model (models.AbstractModel) can not be created, how do you test an abstract model?

Avatar
Annuleer
Beste antwoord

Hi Tyler,

Abstract is a generic model that implements some feature that can then be inherited by regular models in order to make that feature available in them.
So if you want to test abstract model you need to inherit this inside regular model(models.model).
For reference you can look for mail.thread.

Avatar
Annuleer
Auteur

It just seems awkward to have to subclass an AbstractModel in order to test it. There ought to be a way to unit test the AbstractModel when it contains logic that will be inherited by other classes.

Beste antwoord

Usually you create a dummy class that inherits the abstract class and use it for unit testing but in Odoo you don't want test tables in your database. So the trick is to create a distinct module for the sole testing purpose and which you will install on a test database but not on a production database. For example, the mass_mailing application does not have any unit test for its abstract classes. The tests are located in another module called test_mass_mailing which has a models package with some test classes.

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
dec. 22
8258
0
aug. 21
4
1
mrt. 19
18862
3
mei 18
4897
2
nov. 16
3683