我正在使用SpecFlow实现与彼此无关的测试。是否有SpecFlow的配置选项可以启用并行测试执行?我正在使用支持运行“最多5个并行单元测试”的VS10和MSTest运行程序,正如他们在文档中所声称的那样。
谢谢, max.yz
谢谢, max.yz
我从MSTest转向MbUnit来实现这一点。使用ParallelizableAttribute可以在测试夹具级别上实现并行性。然而,由于测试夹具是从.feature Gherkin文件生成的,所以我不得不获取SpecFlow源代码,并修改TechTalk.SpecFlow.Generator项目中的MbUnitTestGeneratorProvider类以输出ParallelizableAttribute。因此,最终你会得到像这样的结果:
public class MbUnitTestGeneratorProvider : IUnitTestGeneratorProvider
{
private const string TESTFIXTURE_ATTR = "MbUnit.Framework.TestFixtureAttribute";
private const string PARALLELIZABLE_ATTR = "MbUnit.Framework.ParallelizableAttribute";
private const string TEST_ATTR = "MbUnit.Framework.TestAttribute";
private const string ROWTEST_ATTR = "MbUnit.Framework.RowTestAttribute";
private const string ROW_ATTR = "MbUnit.Framework.RowAttribute";
private const string CATEGORY_ATTR = "MbUnit.Framework.CategoryAttribute";
private const string TESTSETUP_ATTR = "MbUnit.Framework.SetUpAttribute";
private const string TESTFIXTURESETUP_ATTR = "MbUnit.Framework.FixtureSetUpAttribute";
private const string TESTFIXTURETEARDOWN_ATTR = "MbUnit.Framework.FixtureTearDownAttribute";
private const string TESTTEARDOWN_ATTR = "MbUnit.Framework.TearDownAttribute";
private const string IGNORE_ATTR = "MbUnit.Framework.IgnoreAttribute";
private const string DESCRIPTION_ATTR = "MbUnit.Framework.DescriptionAttribute";
public bool SupportsRowTests { get { return true; } }
public void SetTestFixture(CodeTypeDeclaration typeDeclaration, string title, string description)
{
typeDeclaration.CustomAttributes.Add(
new CodeAttributeDeclaration(
new CodeTypeReference(TESTFIXTURE_ATTR)));
typeDeclaration.CustomAttributes.Add(
new CodeAttributeDeclaration(
new CodeTypeReference(PARALLELIZABLE_ATTR)));
SetDescription(typeDeclaration.CustomAttributes, title);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.6.1.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[MbUnit.Framework.TestFixtureAttribute()]
[MbUnit.Framework.ParallelizableAttribute()]
[MbUnit.Framework.DescriptionAttribute("Test")]
public partial class TestFeature
{
更改测试框架可能会产生干扰。因为我们所有的测试最初都是用 NUnit 编写的,所以我们只需添加新的 SpecRun 运行器,其他什么也不需要改变。对开发人员来说非常简单和透明。而且,由于它可以在 NuGet 上获得,安装也非常容易。