Creating unit tests for your web2py application

Creating unit tests isn't really optional for an App Engine application that uses Cloud SQL because of the way web2py creates the file index.yaml. Web2py generates index.yaml by discovering what indexes it requires as your app uses its database tables. When it encounters new columns (fields) in the table it adds those fields and their sort orders to the list of indexes that need to be created:

It is important always to run your apps locally with the appserver and try every feature of your app before deployment. If you don't do this, performance could suffer because indexes won't be greated. It is also required for automatic generation of the "index.yaml" file.

With applications of any complexity it's not practical to do this by hand, so we'll use unit tests to ensure these indexes get created.

Of course unit tests are generally a good thing in development, period.

Always run your app locally first

Deploying to Cloud SQL is so easy it's temping to send it straight to the cloud without trying it locally first. Try to resist that practice unless you know your unit tests are complete. Otherwise your app won't be able to search and sort properly. Worse, the error messages thrown off by web2py, Google Cloud SQL, and Google App Engine when this happens are not particularly easy to decipher.

Resources

Google groups omnipost, May 2015

Learn web2py through using pytest by Mark Graves is designed to help developers new to testing.

web2py.test by Vinicius Assef.

Web2py.test by Mark Graves builds on the work of Vincinius Assef in an example web2py application.

results matching ""

    No results matching ""