Consider a scenario where a function interacts with a database. How would you mock the database interactions for unit testing this function?

  • Create a separate test database for unit testing
  • Directly connect to the production database for testing
  • Manually insert test data into the production database
  • Use a mocking framework to simulate database responses
By using a mocking framework, you can simulate the behavior of the database interactions without actually accessing the database. This allows for controlled testing without the need for a real database connection, making tests faster and more reliable.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *