简体   繁体   English

在Visual Studio Test Runner中从外部测试套件程序集运行NUnit测试

[英]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. 我最近的模块化结构项目由主程序集(将其命名为app )和多个data-provider Each provider is located in separate repository and implements some basic interface, say IDataProvider . 每个提供程序都位于单独的存储库中,并实现一些基本接口,例如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. 我已经为app存储库中的主要功能编写了一个测试套件(NUnit 3.5)。 And it should be run with each data-provider . 并且应该与每个data-provider一起运行。 This test suite ensures correct provider implementation. 该测试套件可确保正确的提供程序实现。

Therefore I need to run external tests assembly from the particular data-provider . 因此,我需要从特定的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. 当然有环境变量,运行器参数等,但是我不知道如何使Visual Studio Test Runner显示并从UI执行这些测试。

Git Submodules or Git Subtrees can help to maintain link to the main app repository from the separate data-provider repo. Git子模块Git子树可以帮助维护从单独的data-provider存储库到主app存储库的链接。 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 . SimpleProvider项目包含对已编译MainApp.dllMainApp.Tests.dll引用。 I need to run tests from MainApp.Tests.dll inside SimpleProvider project using Visual Studio Test Runner. 我需要使用Visual Studio Test Runner从SimpleProvider项目内的MainApp.Tests.dll运行测试。

I would recommend creating a TestInfrastructure dll that can be shipped to the user creating its data provider. 我建议创建一个TestInfrastructure dll,该DLL可以交付给创建其数据提供程序的用户。 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. 或者,您可以创建一个抽象方法,该方法将返回数据提供者的实例,并让提供者的创建者处理实例化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Visual Studio 2015运行nunit测试 - running nunit tests from visual studio 2015 是从Visual Studio还是从命令行运行程序调用了测试(NUnit3)? - Was a test (NUnit3) invoked from Visual Studio or from a command line runner? NUnit - 在 Visual Studio 中使用测试适配器运行测试时获取结果 xml - NUnit - Getting results.xml when running tests with Test Adapter in Visual Studio NUnit没有运行套件测试 - NUnit not running Suite tests Visual Studio 2013测试运行程序(VSTest)大大降低了测试执行速度 - Visual Studio 2013 Test Runner (VSTest) slows tests execution dramatically 使用 Visual Studio 测试运行器运行的 xUnit 测试的输出未显示在“输出”窗口中 - Output from xUnit tests run with Visual Studio test runner not shown in Output window 单元测试,NUnit或Visual studio? - Unit test, NUnit or Visual studio? Nunit测试套件从脚本运行 - Nunit Test Suite Run From Script Visual Studio 2017(企业)上的 NUnit:Test Runner 仅作为扩展工作,而不是解决方案 NuGet 包? - NUnit on Visual Studio 2017 (Enterprise): Test Runner only works as Extension, not Solution NuGet package? nunit测试中的模态对话框将永远阻止测试运行器 - Modal Dialogs in nunit tests block test runner forever
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM