I got an asp.net MVC application which uses MongoDB database.
Im auto-testing (BDD) it with SpecFlow and Selenium WebDriver, and I want to initialize my database to some state before navigating to some URL or making some acrions. Is it possible to do that ?
I got an asp.net MVC application which uses MongoDB database. Im auto-testing (BDD) it
Share
yes!
I’ve did that in the following way:
1.When tests initialize – generate test database (in most simple way via driver).
2.Make backup (I’ve used mongodump to do that)
3.Before test starts create db with unique name myApp_tests_guid. Keep db name somewhere.
4.Restore database (mongorestore)
5.When test finish or in case of failure — drop database.
6.Optional step for the some specific tests is to adjust common tests database with test specific data.
That’s it. The reason why I’ve used backup/restore approach was performance. Also for the tests make sure that you’ve disabled safe mode and journaling — it will make things faster.