Pact 消费者测试显示在测试资源管理器中,但不运行 .NET

问题描述 投票:0回答:1

我正在使用 PactNet。

我在 github 存储库上编写了与此示例相同的消费者测试:https://github.com/pact-foundation/pact-net

using System.Net;
using PactNet;
using PactNet.Matchers;
using Xunit;

public class SomethingApiConsumerTests
{
    private readonly IPactBuilderV4 pactBuilder;

    public SomethingApiConsumerTests()
    {
        // Use default pact directory ..\..\pacts and default log
        // directory ..\..\logs
        var pact = Pact.V4("Something API Consumer", "Something API", new PactConfig());

        // or specify custom log and pact directories
        pact = Pact.V4("Something API Consumer", "Something API", new PactConfig
        {
            PactDir = $"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName}{Path.DirectorySeparatorChar}pacts"
        });

        // Initialize Rust backend
        this.pactBuilder = pact.WithHttpInteractions();
    }

    [Fact]
    public async Task GetSomething_WhenTheTesterSomethingExists_ReturnsTheSomething()
    {
        // Arrange
        this.pactBuilder
            .UponReceiving("A GET request to retrieve the something")
                .Given("There is a something with id 'tester'")
                .WithRequest(HttpMethod.Get, "/somethings/tester")
                .WithHeader("Accept", "application/json")
            .WillRespond()
                .WithStatus(HttpStatusCode.OK)
                .WithHeader("Content-Type", "application/json; charset=utf-8")
                .WithJsonBody(new
                {
                    id = "tester",
                    firstName = "Totally",
                    lastName = "Awesome"
                });

        await this.pactBuilder.VerifyAsync(async ctx =>
        {
            // Act
            var client = new SomethingApiClient(ctx.MockServerUri);
            var something = await client.GetSomething("tester");

            // Assert
            Assert.Equal("tester", something.Id);
        });
    }
}

我安装了 XUnit 和所需的 NuGet 包,但是测试未运行。

如有任何建议,我们将不胜感激

.net xunit pact pact-net
1个回答
0
投票

无法运行测试通常表明未安装该框架的特定运行程序。假设我们正在讨论 Visual Studio,请确保您已安装

xunit.runner.visualstudio

如果这没有帮助检查运行测试的输出。它应该在尝试执行问题时指示问题。

© www.soinside.com 2019 - 2024. All rights reserved.