1

我在这里看到了这个问题How to execute before and after test run only once in parallel execution of specflow - 尽管我无法理解如何并行运行 Hooks 一次

我使用 Specflow+ Runner 作为我的测试提供者,我的线程数是 3,我有一个 BeforeTestRun 钩子来创建我的测试数据,我只想执行一次该钩子,但默认情况下 BeforeTestRun 在每个线程上运行,我也看过在这里的例子: https ://github.com/SpecFlowOSS/SpecFlow.Plus.Examples/tree/master/CustomDeploymentSteps ,

但我不确定它是如何工作的,谁能帮我解决这个问题。

[BeforeTestRun()]
public static void BeforeTestRun()
{
    Console.WriteLine("test");
}

输出是:

test
test
test

我的 Default.srprofile 看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<TestProfile xmlns="http://www.specflow.org/schemas/plus/TestProfile/1.5">
    <Settings projectName="TestAutoProject" />
    <Execution stopAfterFailures="2" testThreadCount="3" testSchedulingMode="Sequential" />
    <TestAssemblyPaths>
        <TestAssemblyPath>Test.dll</TestAssemblyPath>
    </TestAssemblyPaths>
    <Targets>
        <Target name="IE">
            <Filter>Browser_IE</Filter>
            <DeploymentTransformationSteps>
                <EnvironmentVariable variable="Test_Browser" value="IE" />
            </DeploymentTransformationSteps>
        </Target>
        <Target name="Chrome">
            <Filter>Browser_Chrome</Filter>
            <DeploymentTransformationSteps>
                <EnvironmentVariable variable="Test_Browser" value="Chrome" />
            </DeploymentTransformationSteps>
        </Target>
        <Target name="Firefox">
            <Filter>Browser_Firefox</Filter>
            <DeploymentTransformationSteps>
                <EnvironmentVariable variable="Test_Browser" value="Firefox" />
            </DeploymentTransformationSteps>
        </Target>
    </Targets>
    <DeploymentTransformation>
        <Steps></Steps>
    </DeploymentTransformation>
</TestProfile>
4

0 回答 0