max*_*.yz 8 unit-testing visual-studio-2010 specflow
我正在使用SpecFlow实现与彼此无关的测试.是否有启用并行测试执行的SpecFlow配置选项?我正在使用VS10和MSTest运行器,它支持运行"最多5个并行单元测试",因为他们在文档中声称.
谢谢,max.yz
为了实现这一目标,我从 MSTest 迁移到 MbUnit。您可以使用 ParallelizedAttribute 通过 MbUnit 在测试装置级别实现并行性。然而,由于测试装置是从 .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);
}
Run Code Online (Sandbox Code Playgroud)
如果你编译它并使用它,你最终会得到可并行的测试装置:
[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
{
Run Code Online (Sandbox Code Playgroud)
目前唯一的问题是您需要确保测试装置不会相互冲突。也就是说,来自一个装置的测试添加或修改了数据库行,该行破坏了与其同时运行的测试。有很多方法可以解决这个问题,但这可能超出了您最初问题的范围。
亚历克斯.
| 归档时间: |
|
| 查看次数: |
5627 次 |
| 最近记录: |