Frage

I'm reading the following manual: http://flask.pocoo.org/docs/testing/

Flask has features to simulate requests and check results. The whole application is tested including DB.

It plays nicely with Python module unittest. But this seems to me like end-to-end or functional testing and other tools like Selenium (with Python binding) come to mind.

  1. Is unit-testing is only testing particular module/function/class completely isolated with mocks for external resources (DB, network, files)?

  2. Is it ok to use unit testing frameworks to drive functional\end-to-end tests?

War es hilfreich?

Lösung 2

Flask testing tooling shall serve you well as long as it relates to http communication.

As soon as you create an application, where browser takes significant role by rendering part of output, affecting what can and cannot be done, you should go for solutions like Selenium.

Andere Tipps

Flask does not get in the way of Python/JavaScript testing tooling. For example, it is possible to handle all kinds of testing (I deliberately do not want to name them unit/functional/acceptance/integration tests whatever as there always be anybody who will find the classification wrong):

  • testing simple and/or pure functions or classes
  • as previous plus database (eg, SQLAlchemy) (this is usually more practical and effective than using mocks for ORM/data objects, albeit slower)
  • request-level testing (to test views / routes) - no real HTTP requests, but pretty close for the purpose
  • in-browser testing with real HTTP request, including testing JavaScript modules

For example, with pytest it's just a matter of conftest.py files and fixtures, which provide app, db, http server and Selenium driver (in two separate threads), etc. It is even possible to make certain tests faster by using transaction rollbacks instead of remaking database fixture by substituting (monkeypatching) commit method. During tests, Flask can serve special static folder (by registering test-time only blueprint) to test JavaScript modules using JavaScript-specific testing frameworks of choice.

I guess, other generic testing frameworks (I do not call them unit-testing!) can do the same with more or less boilerplate code and fixture organization.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top