我正在使用SpecFlow实现彼此无关的测试。SpecFlow是否有支持并行测试执行的配置选项?我使用的是VS10和MSTest runner,它们在文档中宣称支持运行“最多5个并行单元测试”。
谢谢,max.yz
发布于 2011-05-24 18:01:49
为了实现这一点,我从MSTest迁移到了MbUnit。您可以使用ParallelizableAttribute在使用MbUnit的测试夹具级别实现并行性。但是,由于测试装置是从.feature小黄瓜文件生成的,因此我必须获取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
{这样做的唯一问题是,您需要确保测试夹具不会相互冲突。也就是说,来自一个fixture的测试添加或修改了一个数据库行,该数据库行破坏了与它同时运行的测试。有一些方法可以绕过这个问题,但这可能超出了您最初的问题的范围。
亚历克斯。
发布于 2012-10-09 02:40:24
SpecFlow的制造者最近发布了一个名为SpecRun的新工具。SpecRun将允许您并行运行这些测试。如果将SpecRun.Nunit包与其一起使用,则可以并行运行NUnit测试。我们在CI服务器上使用SpecRun并行运行测试,但开发人员使用他们选择的任何测试运行器。
更改您的测试框架可能是破坏性的。因为我们所有的测试都是在NUnit中开始的,所以我们简单地添加了新的SpecRun运行器,其他的没有改变。对开发人员来说非常简单和透明。由于它在NuGet上可用,因此安装起来非常容易。
发布于 2015-05-01 13:02:21
我创建了一个生成nant构建文件的解决方案,该文件在自定义并行nant任务中使用nunit:
https://github.com/MartyIce/SpecflowParallelizer
由于我的遗留测试的编写方式,我遇到了后端并发问题,所以对我来说(到目前为止)还不是很成功,但希望这能对其他人起作用。
https://stackoverflow.com/questions/6086889
复制相似问题