Writing tests for code that relies on a SQL Server DB

Joined
Apr 10, 2021
Messages
5
Programming Experience
10+
Hi,

I want add some more tests to a console app that updates a database by consuming a CSV file.

This is a critically important app that currently has no unit tests that verify we update the DB as expected.

I want to add this, I believe I can add a project to the solution that sets up and tears down a temporary DB that allows the unit tests to run with a "real" DB.

In my case this is just a single table and rows are expected to get added from the CSV for records that meet certain criteria.

I've struggled to find a suitable article that can walk me thru this, it's not clear to me what to even search for.

Any help appreciaited
 
If your unit test requires talking to a database, it is not a unit test anymore. It is an integration test. A unit test only exercises a specific chunk of code in isolation, not that chunk of code interfacing with another chunk of code.
 
Anyway, if you want to create this integration test, almost every modern unit testing framework has a way to initialize and teardown a "per session" or "suite wide" state. That would be the place to initialize your database, as well as to delete the database after the tests are done.

What unit testing framework are you using? There maybe a chance that some of the forum users here also use the same framework and can tell you right off the top of their head how to do this setup and teardown.
 
Anyway, if you want to create this integration test, almost every modern unit testing framework has a way to initialize and teardown a "per session" or "suite wide" state. That would be the place to initialize your database, as well as to delete the database after the tests are done.

What unit testing framework are you using? There maybe a chance that some of the forum users here also use the same framework and can tell you right off the top of their head how to do this setup and teardown.

I'm simply using: Microsoft.VisualStudio.TestTools.UnitTesting;

I just want to have the code read a specified test input CSV file and at the same time access a corresponding set of tables that are prepared and populated to match the CSV data.
 
 
Back
Top Bottom