简体   繁体   中英

Running NUnit tests from external test suite assembly in Visual Studio Test Runner

My recent project with modular structure consists of the main assembly (let's name it app ) and multiple data-provider 's. Each provider is located in separate repository and implements some basic interface, say IDataProvider . Any person can implement own provider. I have written a test suite (NUnit 3.5) for main functionality that resides in the app repository. And it should be run with each data-provider . This test suite ensures correct provider implementation.

Therefore I need to run external tests assembly from the particular data-provider . Of course there are environment variables, runner arguments etc, but I don't have a clue how to make Visual Studio Test Runner display and execute those tests from UI.

Git Submodules or Git Subtrees can help to maintain link to the main app repository from the separate data-provider repo. However this approach has some additional caveats.

It's obvious that I'm not the first person to face such problem. Please share your experience.

EDIT :

I'll try to clarify the question. Here is the code of an "app" that resides in "main-app" repository.

// repository "main-app"
namespace MainApp
{
    public interface IDataProvider
    {
        string Concat(params string[] arg);
    }
}
namespace MainApp.Tests
{
    [TestFixture]
    public class SampleTests
    {
        [Test]
        public void GetDataTest(IDataProvider provider)
        {
            Assert.AreEqual("ab", provider.Concat("a", "b"));
        }
    }
}

And here is the provider implementation (resides in the separate repository)

// repository "simple-provider"
namespace MainApp.SimpleProvider
{
    public class SimpleProvider : IDataProvider
    {
        public string Concat(params string[] arg)
        {
            return string.Concat(arg);
        }
    }
}

SimpleProvider project conatins references to compiled MainApp.dll and MainApp.Tests.dll . I need to run tests from MainApp.Tests.dll inside SimpleProvider project using Visual Studio Test Runner.

I would recommend creating a TestInfrastructure dll that can be shipped to the user creating its data provider. Then the user can create a test class inheriting from your base class to run the common tests.

namespace MainApp.SimpleProvider.Tests
{
    [TestFixture]
    public class SimpleProviderTests : DataProviderTests
    {
        // Add here specific tests if you want.
    }
}

You can use generics if you want to run the tests by casting to some type. Or you can create an abstract method that will return an instance of the dataprovider and let the creator of the provider handling the instantiation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM