Xunit retryFact属性如何工作?

发布于 2025-01-24 15:42:27 字数 206 浏览 1 评论 0原文

我的硒测试由Xunit运行。我在C#上写测试。某些测试不稳定(尤其是使用鼠标动作的测试)。我在Xunit中找到了retryFactattribute,但找不到任何文档。

我目前的主要问题是:如果我使用[retryfact(delaybetweenretriesms:3000)]

如果可以的话,请建议我在其中找到有关属性的更多信息的资源。

I have Selenium tests which are run by XUnit. I write tests on c#. Some of the tests are not stable (especially those which uses mouse actions). I found the RetryFactAttribute in XUnit but I can't find any documetation for it.

My main question for now: will xUnit run other tests while waiting 3 seconds if I use [RetryFact(delayBetweenRetriesMs: 3000)] ?

If you can, please suggest resource where I can find more information about the attribute.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过度放纵 2025-01-31 15:42:27

它似乎是如何使用自定义ixunittestCasediscovererxunittestcase的示例。您可以找到示例源代码

Ultimately it's just an attribute with the following attribute attached to it:

[XunitTestCaseDiscoverer("RetryFactExample.RetryFactDiscoverer", "RetryFactExample")]

Which then indirectly references

public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink,
                                                IMessageBus messageBus,
                                                object[] constructorArguments,
                                                ExceptionAggregator aggregator,
                                                CancellationTokenSource cancellationTokenSource)
{
    var runCount = 0;

    while (true)
    {
        // This is really the only tricky bit: we need to capture and delay messages (since those will
        // contain run status) until we know we've decided to accept the final result;
        var delayedMessageBus = new DelayedMessageBus(messageBus);

        var summary = await base.RunAsync(diagnosticMessageSink, delayedMessageBus, constructorArguments, aggregator, cancellationTokenSource);
        if (aggregator.HasExceptions || summary.Failed == 0 || ++runCount >= maxRetries)
        {
            delayedMessageBus.Dispose();  // Sends all the delayed messages
            return summary;
        }

        diagnosticMessageSink.OnMessage(new DiagnosticMessage("Execution of '{0}' failed (attempt #{1}), retrying...", DisplayName, runCount));
    }
}

我不确定您的问题是否会在单个测试中阻止单个测试3秒钟,但是从这个问题来看,我认为答案可能是“是”。最好在实验上测试这一问题。

It appears to be an example of how to use a custom IXunitTestCaseDiscoverer and XunitTestCase. You can find the example source code here.

Ultimately it's just an attribute with the following attribute attached to it:

[XunitTestCaseDiscoverer("RetryFactExample.RetryFactDiscoverer", "RetryFactExample")]

Which then indirectly references RetryTestCase.cs (a derivative of XunitTestCase) where its actual behaviour is defined:

public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink,
                                                IMessageBus messageBus,
                                                object[] constructorArguments,
                                                ExceptionAggregator aggregator,
                                                CancellationTokenSource cancellationTokenSource)
{
    var runCount = 0;

    while (true)
    {
        // This is really the only tricky bit: we need to capture and delay messages (since those will
        // contain run status) until we know we've decided to accept the final result;
        var delayedMessageBus = new DelayedMessageBus(messageBus);

        var summary = await base.RunAsync(diagnosticMessageSink, delayedMessageBus, constructorArguments, aggregator, cancellationTokenSource);
        if (aggregator.HasExceptions || summary.Failed == 0 || ++runCount >= maxRetries)
        {
            delayedMessageBus.Dispose();  // Sends all the delayed messages
            return summary;
        }

        diagnosticMessageSink.OnMessage(new DiagnosticMessage("Execution of '{0}' failed (attempt #{1}), retrying...", DisplayName, runCount));
    }
}

I'm not 100% sure about your question re whether it will block on a single test for 3 seconds, but judging by this I think the answer is probably "yes". It's best to test this experimentally to be sure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文