• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unit testing with database in CI 3.x

#1
Hello all,

I have started writing Unit tests for an existing application. I am testing with database. I wanted to know if is there a way reinitialize MySQL back to its state before running the test. What am looking for is suggestions and resources. Thanks all.
Reply

#2
What do you mean by reinitialize MySQL Database?

Back to an empty database or what?

If it's back to an empty database then all you need to do is delete all the tables.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#3
(03-15-2017, 04:07 PM)InsiteFX Wrote: What do you mean by reinitialize MySQL Database?

Back to an empty database or what?

If it's back to an empty database then all you need to do is delete all the tables.

Sorry for the misunderstanding. I meant that I have a database at a certain state. I am testing my models, and some tests insert and delete info from the database, I want the database to go back to the state it was before running the tests.
Reply

#4
You would need to make an sql dump of the normal state then delete all tables and run the sql dump to put it back.

You can do this using CodeIgniter Query Builder.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#5
(03-16-2017, 01:29 PM)InsiteFX Wrote: You would need to make an sql dump of the normal state then delete all tables and run the sql dump to put it back.

You can do this using CodeIgniter Query Builder.

Thank you
Reply

#6
If you use ci-phpunit-test, it provides sample database seeders.
See https://github.com/kenjis/ci-phpunit-tes...se-seeding
Do you want to write tests for your apps? Our book, CodeIgniter Testing Guide would help you.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.