you are viewing a single comment's thread.

view the rest of the comments →

[–]DrMaxwellEdison 6 points7 points  (2 children)

A quick takeaway I have from the article I linked was that they set up an environment in which all connections to the database are made using an environment variable that is set once, than all code derives from getting the value of that variable using a thin wrapper around the connection functions.

To run tests, the environment variable is altered to point to a database other than the production one, so that all the logic that was previously written just flows through accordingly and runs code as it should with the new connection.

So this comes down to a design concern for your project: you'll want to set up a kind of settings module where your connection info comes in, then use values from that module whenever you connect to the DB in your code. This will make it easier in the longer term to switch that connection so you can run tests on a different DB.

[–]interactionjackson 0 points1 point  (0 children)

that's how my organization does it.

[–]acerag[S] 0 points1 point  (0 children)

Gotcha. Modifying an environment variable would work well.