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.