In one of my current projects I had the following code (I simplified the code a bit):public string ConnectionString
{
get
{
switch(this.Importer)
{
case Importer.SqlServer:
return "Server=localhost;Database=Northwind";
case Importer.SqlServerOleDb:
return"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind";
default:
throw new NotSupportedException(
string.Format("Importer {0} is not supported yet.", this.Importer));
}
}
}After running the code coverage tool (dotCover from JetBrains) I received the following picture: First ideaSo, my code was clear and understandable, but obviously not fully tested (green: covered by tests, red: not covered). I asked me the question, how could I test the rest of the method.My idea was to extend the enum: [TestFixture]
public class ConfigurationTest
{
#region Test methods
{
get
{
switch(this.Importer)
{
case Importer.SqlServer:
return "Server=localhost;Database=Northwind";
case Importer.SqlServerOleDb:
return"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind";
default:
throw new NotSupportedException(
string.Format("Importer {0} is not supported yet.", this.Importer));
}
}
}After running the code coverage tool (dotCover from JetBrains) I received the following picture: First ideaSo, my code was clear and understandable, but obviously not fully tested (green: covered by tests, red: not covered). I asked me the question, how could I test the rest of the method.My idea was to extend the enum: [TestFixture]
public class ConfigurationTest
{
#region Test methods
0 comments:
Post a Comment