lundi 21 septembre 2015

Do I have to create my test database entries in each TestCase?

I have a ecommerce application where I have sub-applications such as product, order, checkout and so on. In each application I have a tests.py file containing test for that isolated part of the app.

Many of the different testcases/sub-apps use the same kind of data. For example, both product-tests, order-tests and checkout-tests need to have sample data for products, carts, currencies and so on.

Currently I'm creating this test data in the setUp function of each TestCase. But this means that I'm creating the same data over and over again, which seem very stupid and unnecessary.

Is there some way for me to create "global" test data for my test-database? That will be created first, before any TestCase is run? Or am I already doing the "correct" way, even though it seems bad?

I'm using Django, which is using the unittest python module.

Aucun commentaire:

Enregistrer un commentaire