[英]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.dll
和MainApp.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.