jeudi 28 avril 2016

Share DB setup data between multiple unit test classes

I'm not sure if true unit tests should strictly interact with external systems like databases, but mine do - the idea being my setup code ensures the DB is in a certain state, then my unit tests expect certain results from methods that get called; I need to check the DB-access code is doing the right thing.

I want to use the same DB test data in multiple test classes and not copy-paste it into each class' [TestInitialize] and I'm wondering how best to do this. Options seem to include:

  1. Throw it all in an external .sql script and run this
  2. Some sort of helper class with a static method

I would prefer the code to update the DB is part of my C# code but wondered if there is a more typical way MSTest projects might handle this?

Aucun commentaire:

Enregistrer un commentaire