I'm creating an application with plugin architecture and I'd like to create generic tests for plugins, since extension points are well defined. Plugins will have their own tests for testing internal stuff.
What is a preferred way to create these tests, so that every plugin doesn't need include tests for the "obvious" stuff? I am interested in, how such tests are made in relation to unit-testing framework.
It should be enough, if someone pointed me at an open-source project, which does have such generic tests for plugins. My application is made in C# (and MEF for composition), so projects written in similar (strongly-typed) languages (like Java) are preferred.
Seems like putting generic tests into a base class and deriving from it for each plugin is a viable way:
public interface IPluginComponent
{
}
[TestClass]
public abstract class BaseTests
{
protected abstract IPluginComponent CreateComponent();
[TestMethod]
public void SomeTest()
{
IPluginComponent component = this.CreateComponent();
// execute test
}
}
public class MyPluginComponent : IPluginComponent
{
}
[TestClass]
public class MyPluginTests : BaseTests
{
protected IPluginComponent CreateComponent()
{
return new MyPluginComponent();
}
[TestMethod]
public void CustomTest()
{
// custom test
}
}
Tests using MSTest should however be aware of a bug, where it is not possible to run tests in base class, if base class is located in a different assembly. This was not fixed in Visual Studio 2010, not sure about 2012: