Ignore integration tests when provider is missing

As an integration test I’ve written some unit tests for my MsAccess Data Access Layer. The provider I’m using is OleDb. It will be installed on every desktop machine, but not on our build server.

The build fails because of the missing provider. So, we decided to ignore the tests when the provider was missing. See the boilerplate code below

static List<string> Providers;
static GMCDatabaseFileUser() {
   Providers = new List<string>();
   var reader = System.Data.OleDb.OleDbEnumerator.GetRootEnumerator();
   while (reader.Read()) {
      for (var i = 0; i < reader.FieldCount; i++) {
         if (reader.GetName(i) == "SOURCES_NAME") {
            Providers.Add(reader.GetValue(i).ToString());
            Trace.WriteLine(reader.GetValue(i).ToString());
         }
      }
   }
   reader.Close();
}
static void EnsureProvider() {
   var provider = "Microsoft.ACE.OLEDB.12.0";
   if (!Providers.Contains(provider)) {
      Assert.Inconclusive("Missing {0}", provider);
   }
}

Now I can simply call the logic in every unit test and have it ignored when the provider is missing.

[TestMethod]
public void MyProviderNeedingTest()
{
   EnsureProvider();
   // provider needing test
}

How will I know this happened on the build server? Check your code coverage, it’ll be less than you expect. Also the ignored tests are in the log.

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s