Unit tests in a database-based CodeIgniter web application

CodeIgniter comes with a built-in testing module, and I would really like to use it. However, almost all the functions that I would like to test interact with the database, adding records, deleting records, etc. For example, how will I write tests for the "create user" function, without actually creating users each time I run the test?

With some further research, it seems to me that I need to use Mock objects for external services such as a database, etc. I have not been able to find much information on how to do this except this one forum: http://codeigniter.com/forums/viewthread/106737

Is there any actual documentation?

+6
source share
1 answer

If your database driver allows transactions, use them. Do everything you need to test, then rollback (by success or failure).

I found it difficult to run unit tests using controller actions. If you find a good way to do this, let us know!

+4
source

Source: https://habr.com/ru/post/908061/


All Articles