Reo.Core.Xunit.IntegrationTesting 6.0.31862

There is a newer version of this package available.
See the version list below for details.
dotnet add package Reo.Core.Xunit.IntegrationTesting --version 6.0.31862
NuGet\Install-Package Reo.Core.Xunit.IntegrationTesting -Version 6.0.31862
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Reo.Core.Xunit.IntegrationTesting" Version="6.0.31862" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Reo.Core.Xunit.IntegrationTesting --version 6.0.31862
#r "nuget: Reo.Core.Xunit.IntegrationTesting, 6.0.31862"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Reo.Core.Xunit.IntegrationTesting as a Cake Addin
#addin nuget:?package=Reo.Core.Xunit.IntegrationTesting&version=6.0.31862

// Install Reo.Core.Xunit.IntegrationTesting as a Cake Tool
#tool nuget:?package=Reo.Core.Xunit.IntegrationTesting&version=6.0.31862

Xunit.IntegrationTesting

Расширение фреймворка xUnit для выполнения интеграционного тестирования

Использование

Первоначальная настройка

В проекте с тестами необходимо определить файл со следующим содержимым:

using Reo.Core.IntegrationTesting.TestFramework.Mongo;
using Reo.Core.IntegrationTesting.TestFramework.Postgres;
using Reo.Core.Xunit.IntegrationTesting.Attributes;

[assembly:EnableIntegrationTestingFramework]
[assembly:RaiseContainer<PostgresTestContainer<TestingContext>>]
[assembly:RaiseContainer<MongoTestContainer>]

Атрибут EnableIntegrationTestingFramework должен быть указан в обязательном порядке. Он указывает xUnit, что необходимо использовать расширенный тестовый фреймворк вместо обычного.

Атрибут RaiseContainer нужен для того, чтобы при запуске тестов запустился контейнер указанного типа. В прошлом контейнеры запускались при старте каждого тестового класса, теперь запускается единственный контейнер для всех тестов примерно сразу после загрузки сборки.

На данный момент реализованы четыре контейнера (их можно найти в пакете Reo.Core.IntegrationTesting):

  • Postgres (PostgresTestContainer{TDbContext} и PostgresFixture{TDbContext})
  • Mongo (MongoTestContainer и MongoFixture)
  • Redis (RedisTestContainer и RedisFixture)
  • Elastic (ElasticTestContainer и ElasticFixture)
Написание тестов

В тестовом классе необходимо указать какую фикстуру вы хотите использовать.

CollectionFixture

Фикстура создается один раз на запускаемую пачку тестов

// CollectionDefinition.cs

[CollectionDefinition(nameof(PostgresDefinition))]
public sealed class PostgresDefinition : ICollectionFixture<PostgresFixture<TestingDbContext>>
{ }
// TestClass.cs

[Collection(nameof(PostgresDefinition))]
public sealed class TestClass
{
    private readonly PostgresFixture<TestingDbContext> _fixture;

    public TestClass(PostgresFixture<TestingDbContext> fixture)
    {
        _fixture = fixture;
    }

    [Fact]
    public void Verify()
    {
        // ...
    }
}

К сожалению, CollectionDefinition необходимо описывать в каждой сборке, иначе xUnit их не увидит (см. документацию xUnit)

ClassFixture

Фикстура создается один раз на запускаемый тестовый класс

public sealed class TestClass : IClassFixture<MongoFixture>
{
    private readonly MongoFixture _fixture;

    public TestClass(MongoFixture fixture)
    {
        _fixture = fixture;
    }

    [Fact]
    public void Verify()
    {
        // ...
    }
}

И то, и другое

xUnit не запрещает внедрять IClassFixture и ICollectionFixture одновременно:

[Collection(nameof(PostgresDefinition))]
public sealed class TestClass : IClassFixture<MongoFixture>
{
    // ...

    public TestClass(PostgresFixture<TestingDbContext> postgresFixture, MongoFixture mongoFixture)
    {
    	// ...
    }

    // ...
}

Сидирование данных

Чтобы проинициализировать справочники, вы должны реализовать абстрактный класс ContainerSeeder

public sealed class PostgresSeeder : ContainerSeeder<PostgresFixture<TestingContext>>
{
    /// <inheritdoc />
    public override async Task SeedAsync(PostgresFixture<TestingContext> fixture)
    {
        await using var databaseContext =
            await fixture.DatabaseContextFactory.CreateDbContextAsync();

        databaseContext.References.Add(new()
        {
            Id = Guid.NewGuid(),
            Name = "Profile test"
        });

        await databaseContext.SaveChangesAsync();
    }
}

Сид не должен содержать конструкторов, кроме стандартного. Количество сидов для одной фикстуры не ограничено.

Немного про очистку базы данных после исполнения конкретного теста

Если после каждого теста вы хотите откатывать ее в первоначальное состояние - используйте метод CleanupAsync, определенной у каждой фикстуры:

public sealed class Tests : IClassFixture<PostgresFixture<TestingContext>>, IAsyncLifetime
{
    private readonly PostgresFixture<TestingContext> _fixture;

    public ContainerSeederTests(PostgresFixture<TestingContext> fixture)
        => _fixture = fixture;

    public async Task InitializeAsync()
    {
        await using var databaseContext =
            await _fixture.DatabaseContextFactory.CreateDbContextAsync();

        databaseContext.Entities.Add(new()
        {
            Id = Guid.NewGuid()
        });

        await databaseContext.SaveChangesAsync();
    }

    [Theory]
    [InlineData(1)]
    [InlineData(2)]
    [InlineData(3)]
    public async Task Verify(int _)
    {
        // Благодаря _fixture.CleanupAsync() в базе всегда будет 1 запись, добавленная в InitializeAsync()
    }


    public Task DisposeAsync()
        => _fixture.CleanupAsync();
}

Метод CleanupAsync очищает базу данных и повторно выполняет сидирование справочников

Регистрация артефактов из фикстуры в AutoMocker

При внедрении фикстуры используйте готовые методы расширения:

public sealed class TestClass :
    IClassFixture<PostgresFixture<TestingDbContext>>,
    IClassFixture<MongoFixture>,
    IClassFixture<ElasticFixture>,
    IClassFixture<RedisFixture>
{
    private readonly AutoMocker _mocker = new();

    // ...

    public TestClass(
        PostgresFixture<TestingDbContext> postgresFixture,
        MongoFixture mongoFixture,
        ElasticFixture elasticFixture,
        RedisFixture redisFixture)
    {
    	// ...

        _mocker
            .SetupPostgres(postgresFixture)
            .SetupMongo(mongoFixture)
            .SetupElastic(elasticFixture)
            .SetupRedis(redisFixture);
    }

    // ...
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Reo.Core.Xunit.IntegrationTesting:

Package Downloads
Reo.Core.IntegrationTesting

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.31906 14 6/27/2024
6.0.31905 26 6/27/2024
6.0.31904 27 6/27/2024
6.0.31903 28 6/27/2024
6.0.31902 39 6/27/2024
6.0.31901 46 6/26/2024
6.0.31900 43 6/26/2024
6.0.31899 58 6/26/2024
6.0.31898 56 6/26/2024
6.0.31897 59 6/26/2024
6.0.31896 63 6/26/2024
6.0.31894 67 6/25/2024
6.0.31893 69 6/25/2024
6.0.31892 68 6/25/2024
6.0.31891 68 6/25/2024
6.0.31890 66 6/25/2024
6.0.31887 69 6/25/2024
6.0.31886 69 6/25/2024
6.0.31885 71 6/24/2024
6.0.31884 69 6/24/2024
6.0.31883 82 6/23/2024
6.0.31882 75 6/21/2024
6.0.31881 74 6/21/2024
6.0.31880 70 6/21/2024
6.0.31879 72 6/20/2024
6.0.31878 95 6/19/2024
6.0.31877 86 6/19/2024
6.0.31876 88 6/19/2024
6.0.31875 92 6/19/2024
6.0.31874 83 6/19/2024
6.0.31873 84 6/19/2024
6.0.31872 97 6/19/2024
6.0.31871 84 6/19/2024
6.0.31870 88 6/19/2024
6.0.31869 82 6/19/2024
6.0.31868 96 6/18/2024
6.0.31867 81 6/18/2024
6.0.31866 95 6/18/2024
6.0.31865 93 6/18/2024
6.0.31864 92 6/18/2024
6.0.31863 82 6/18/2024
6.0.31862 90 6/18/2024
6.0.31861 80 6/18/2024
6.0.31860 87 6/17/2024
6.0.31859 87 6/17/2024
6.0.31858 83 6/17/2024
6.0.31857 86 6/17/2024
6.0.31856 93 6/17/2024
6.0.31855 84 6/17/2024
6.0.31854 84 6/17/2024
6.0.31853 92 6/17/2024
6.0.31852 91 6/17/2024
6.0.31851 89 6/17/2024
6.0.31850 88 6/17/2024
6.0.31849 83 6/17/2024
6.0.31848 88 6/15/2024
6.0.31847 86 6/15/2024
6.0.31846 77 6/14/2024
6.0.31845 91 6/14/2024
6.0.31844 91 6/14/2024
6.0.31843 80 6/14/2024
6.0.31842 87 6/14/2024
6.0.31841 84 6/13/2024
6.0.31840 91 6/13/2024
6.0.31839 88 6/13/2024
6.0.31838 82 6/13/2024
6.0.31837 86 6/13/2024
6.0.31836 86 6/13/2024
6.0.31835 86 6/13/2024
6.0.31834 82 6/13/2024
6.0.31833 74 6/12/2024
6.0.31832 71 6/12/2024
6.0.31831 70 6/11/2024
6.0.31830 69 6/11/2024
6.0.31829 68 6/11/2024
6.0.31828 70 6/11/2024
6.0.31827 73 6/11/2024
6.0.31826 68 6/11/2024
6.0.31825 77 6/10/2024
6.0.31824 69 6/10/2024
6.0.31823 71 6/10/2024
6.0.31822 72 6/10/2024
6.0.31821 71 6/10/2024
6.0.31820 72 6/10/2024
6.0.31819 73 6/10/2024
6.0.31818 68 6/10/2024
6.0.31817 73 6/7/2024
6.0.31816 74 6/7/2024
6.0.31815 78 6/7/2024
6.0.31814 83 6/6/2024
6.0.31813 81 6/6/2024
6.0.31812 86 6/6/2024
6.0.31811 80 6/6/2024
6.0.31810 85 6/6/2024
6.0.31809 84 6/6/2024
6.0.31808 80 6/6/2024
6.0.31807 82 6/5/2024
6.0.31806 91 6/4/2024
6.0.31805 84 6/4/2024
6.0.31804 82 6/4/2024
6.0.31803 84 6/4/2024
6.0.31802 84 6/4/2024
6.0.31801 88 6/3/2024
6.0.31800 84 6/3/2024
6.0.31799 76 6/3/2024
6.0.31798 77 6/3/2024
6.0.31797 68 6/3/2024
6.0.31796 83 6/3/2024
6.0.31795 90 6/3/2024
6.0.31794 100 5/31/2024
6.0.31793 100 5/30/2024
6.0.31792 93 5/30/2024
6.0.31791 90 5/30/2024
6.0.31790 87 5/30/2024
6.0.31789 88 5/30/2024
6.0.31788 92 5/30/2024
6.0.31787 93 5/29/2024
6.0.31786 85 5/29/2024
6.0.31785 89 5/29/2024
6.0.31784 80 5/29/2024
6.0.31783 99 5/27/2024
6.0.31782 84 5/27/2024
6.0.31781 95 5/26/2024
6.0.31780 89 5/24/2024
6.0.31779 92 5/22/2024
6.0.31778 99 5/22/2024
6.0.31777 86 5/22/2024
6.0.31776 92 5/22/2024
6.0.31775 91 5/22/2024
6.0.31774 82 5/21/2024
6.0.31773 82 5/21/2024
6.0.31772 94 5/20/2024
6.0.31771 90 5/16/2024
6.0.31770 80 5/15/2024
6.0.31769 90 5/15/2024
6.0.31768 93 5/15/2024
6.0.31767 78 5/15/2024
6.0.31766 94 5/15/2024
6.0.31764 85 5/14/2024
6.0.31763 80 5/14/2024
6.0.31762 79 5/14/2024
6.0.31761 86 5/14/2024
6.0.31760 89 5/14/2024
6.0.31759 92 5/13/2024
6.0.31758 90 5/13/2024
6.0.31757 80 5/13/2024
6.0.31756 82 5/12/2024
6.0.31755 84 5/12/2024
6.0.31754 90 5/12/2024
6.0.31753 95 5/8/2024
6.0.31751 99 5/7/2024
6.0.31749 98 5/6/2024
6.0.31748 102 5/6/2024
6.0.31747 106 5/6/2024
6.0.31746 68 5/3/2024
6.0.31745 55 5/3/2024
6.0.31744 57 5/3/2024
6.0.31743 55 5/2/2024
6.0.31742 100 4/27/2024
6.0.31741 98 4/27/2024
6.0.31740 100 4/26/2024
6.0.31739 93 4/26/2024
6.0.31738 108 4/26/2024
6.0.31737 108 4/26/2024
6.0.31735 111 4/25/2024
6.0.31734 93 4/25/2024
6.0.31733 92 4/25/2024
6.0.31732 95 4/25/2024
6.0.31731 83 4/25/2024
6.0.31730 100 4/24/2024
6.0.31729 91 4/24/2024
6.0.31728 96 4/24/2024
6.0.31727 92 4/23/2024
6.0.31726 78 4/23/2024
6.0.31725 92 4/23/2024
6.0.31724 94 4/22/2024
6.0.31723 94 4/22/2024
6.0.31722 101 4/22/2024
6.0.31721 99 4/22/2024
6.0.31720 92 4/22/2024
6.0.31719 90 4/22/2024
6.0.31718 92 4/22/2024
6.0.31717 94 4/22/2024
6.0.31716 90 4/22/2024
6.0.31715 105 4/20/2024
6.0.31714 104 4/19/2024
6.0.31713 82 4/19/2024
6.0.31712 80 4/19/2024
6.0.31711 96 4/19/2024
6.0.31710 82 4/19/2024
6.0.31709 90 4/19/2024
6.0.31708 91 4/18/2024
6.0.31707 86 4/18/2024
6.0.31706 84 4/18/2024
6.0.31705 83 4/17/2024
6.0.31704 104 4/17/2024
6.0.31703 92 4/17/2024
6.0.31702 93 4/17/2024
6.0.31701 89 4/16/2024
6.0.31700 87 4/16/2024
6.0.31699 89 4/16/2024
6.0.31698 83 4/16/2024
6.0.31697 84 4/16/2024
6.0.31696 82 4/16/2024
6.0.31695 79 4/16/2024
6.0.31694 85 4/16/2024
6.0.31693 85 4/16/2024
6.0.31692 82 4/15/2024
6.0.31691 83 4/15/2024
6.0.31690 94 4/15/2024
6.0.31688 100 4/12/2024
6.0.31687 79 4/12/2024
6.0.31686 83 4/12/2024
6.0.31685 81 4/12/2024
6.0.31684 81 4/11/2024
6.0.31683 91 4/10/2024
6.0.31682 83 4/10/2024
6.0.31681 82 4/10/2024
6.0.31680 88 4/10/2024
6.0.31679 78 4/10/2024
6.0.31678 79 4/10/2024
6.0.31677 91 4/9/2024
6.0.31676 96 4/9/2024
6.0.31675 92 4/8/2024
6.0.31674 99 4/8/2024
6.0.31673 101 4/8/2024
6.0.31672 79 4/8/2024
6.0.31671 79 4/8/2024
6.0.31670 89 4/8/2024
6.0.31669 86 4/8/2024
6.0.31668 94 4/5/2024
6.0.31667 95 4/5/2024
6.0.31666 103 4/3/2024
6.0.31665 94 4/3/2024
6.0.31663 98 4/3/2024
6.0.31662 90 4/3/2024
6.0.31661 94 4/2/2024
6.0.31660 95 4/1/2024
6.0.31659 86 4/1/2024
6.0.31658 83 4/1/2024
6.0.31657 89 3/29/2024
6.0.31656 83 3/29/2024
6.0.31655 86 3/29/2024
6.0.31654 94 3/29/2024
6.0.31653 79 3/29/2024
6.0.31651 74 3/29/2024
6.0.31650 79 3/29/2024
6.0.31649 80 3/29/2024
6.0.31648 80 3/29/2024
6.0.31647 78 3/29/2024
6.0.31646 100 3/29/2024
6.0.31645 83 3/28/2024
6.0.31644 85 3/28/2024
6.0.31643 91 3/28/2024
6.0.31642 86 3/28/2024
6.0.31639 90 3/28/2024
6.0.31638 75 3/28/2024
6.0.31637 99 3/27/2024
6.0.31636 121 3/27/2024
6.0.31631 90 3/27/2024
6.0.31626 97 3/26/2024
6.0.31625 104 3/25/2024
6.0.31618 102 3/20/2024
6.0.31617 93 3/20/2024
6.0.31616 104 3/20/2024
6.0.31615 92 3/20/2024
6.0.31614 112 3/19/2024
6.0.31613 107 3/18/2024
6.0.31612 117 3/18/2024
6.0.31611 118 3/18/2024
6.0.31610 111 3/18/2024
6.0.31609 104 3/15/2024
6.0.31608 104 3/14/2024
6.0.31607 116 3/13/2024
6.0.31606 104 3/13/2024
6.0.31605 102 3/13/2024
6.0.31604 100 3/12/2024
6.0.31603 99 3/12/2024
6.0.31602 130 3/7/2024
6.0.31601 106 3/7/2024
6.0.31600 115 3/7/2024
6.0.31599 110 3/6/2024
6.0.31598 101 3/6/2024
6.0.31597 106 3/6/2024
6.0.31596 104 3/6/2024
6.0.31595 115 3/6/2024
6.0.31594 104 3/4/2024
6.0.31593 92 3/4/2024
6.0.31590 100 3/1/2024
6.0.31589 95 3/1/2024
6.0.31588 99 3/1/2024
6.0.31587 89 3/1/2024
6.0.31586 98 3/1/2024
6.0.31585 87 3/1/2024
6.0.31584 99 3/1/2024
6.0.31583 90 3/1/2024
6.0.31582 101 2/29/2024
6.0.31581 93 2/29/2024
6.0.31580 99 2/29/2024
6.0.31579 104 2/29/2024
6.0.31578 102 2/29/2024
6.0.31577 97 2/29/2024
6.0.31576 102 2/29/2024
6.0.31575 101 2/28/2024