Reo.Core.Xunit.IntegrationTesting 6.0.31638

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.31638                
NuGet\Install-Package Reo.Core.Xunit.IntegrationTesting -Version 6.0.31638                
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.31638" />                
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.31638                
#r "nuget: Reo.Core.Xunit.IntegrationTesting, 6.0.31638"                
#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.31638

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

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.31994 0 9/20/2024
6.0.31993 0 9/20/2024
6.0.31992 4 9/20/2024
6.0.31991 36 9/19/2024
6.0.31990 64 9/17/2024
6.0.31989 55 9/16/2024
6.0.31988 64 9/16/2024
6.0.31987 65 9/16/2024
6.0.31986 58 9/16/2024
6.0.31985 72 9/13/2024
6.0.31984 70 9/13/2024
6.0.31983 75 9/13/2024
6.0.31982 78 9/12/2024
6.0.31981 69 9/12/2024
6.0.31980 68 9/12/2024
6.0.31979 68 9/12/2024
6.0.31978 77 9/12/2024
6.0.31977 103 9/11/2024
6.0.31976 97 9/11/2024
6.0.31975 96 9/11/2024
6.0.31974 107 9/6/2024
6.0.31973 99 9/5/2024
6.0.31972 79 9/4/2024
6.0.31971 77 9/2/2024
6.0.31970 88 8/28/2024
6.0.31969 89 8/28/2024
6.0.31968 97 8/27/2024
6.0.31967 88 8/26/2024
6.0.31966 105 8/21/2024
6.0.31965 133 8/19/2024
6.0.31964 95 8/19/2024
6.0.31963 96 8/19/2024
6.0.31962 117 8/15/2024
6.0.31961 122 8/13/2024
6.0.31960 110 8/12/2024
6.0.31959 97 8/12/2024
6.0.31958 77 8/7/2024
6.0.31957 76 8/7/2024
6.0.31956 62 8/6/2024
6.0.31955 69 8/6/2024
6.0.31954 66 8/6/2024
6.0.31953 73 8/6/2024
6.0.31952 69 8/5/2024
6.0.31951 63 8/2/2024
6.0.31950 62 8/2/2024
6.0.31949 68 8/2/2024
6.0.31948 78 8/1/2024
6.0.31947 57 7/31/2024
6.0.31946 78 7/30/2024
6.0.31945 46 7/30/2024
6.0.31944 61 7/25/2024
6.0.31943 47 7/25/2024
6.0.31942 89 7/24/2024
6.0.31941 89 7/24/2024
6.0.31940 99 7/22/2024
6.0.31939 85 7/22/2024
6.0.31938 90 7/22/2024
6.0.31937 107 7/21/2024
6.0.31936 83 7/19/2024
6.0.31935 71 7/19/2024
6.0.31934 82 7/19/2024
6.0.31933 80 7/18/2024
6.0.31932 83 7/18/2024
6.0.31931 73 7/18/2024
6.0.31930 69 7/18/2024
6.0.31929 74 7/16/2024
6.0.31928 79 7/16/2024
6.0.31927 74 7/16/2024
6.0.31926 75 7/16/2024
6.0.31925 74 7/16/2024
6.0.31924 68 7/16/2024
6.0.31921 74 7/15/2024
6.0.31920 73 7/15/2024
6.0.31919 80 7/15/2024
6.0.31918 73 7/11/2024
6.0.31917 67 7/11/2024
6.0.31916 79 7/11/2024
6.0.31915 72 7/11/2024
6.0.31914 84 7/10/2024
6.0.31913 86 7/10/2024
6.0.31912 81 7/10/2024
6.0.31911 76 7/10/2024
6.0.31910 103 7/4/2024
6.0.31909 89 7/3/2024
6.0.31908 97 7/3/2024
6.0.31907 101 7/2/2024
6.0.31906 100 6/27/2024
6.0.31905 99 6/27/2024
6.0.31904 101 6/27/2024
6.0.31903 97 6/27/2024
6.0.31902 84 6/27/2024
6.0.31901 92 6/26/2024
6.0.31900 86 6/26/2024
6.0.31899 85 6/26/2024
6.0.31898 83 6/26/2024
6.0.31897 86 6/26/2024
6.0.31896 78 6/26/2024
6.0.31894 84 6/25/2024
6.0.31893 90 6/25/2024
6.0.31892 83 6/25/2024
6.0.31891 83 6/25/2024
6.0.31890 81 6/25/2024
6.0.31887 83 6/25/2024
6.0.31886 84 6/25/2024
6.0.31885 85 6/24/2024
6.0.31884 83 6/24/2024
6.0.31883 107 6/23/2024
6.0.31882 88 6/21/2024
6.0.31881 87 6/21/2024
6.0.31880 83 6/21/2024
6.0.31879 98 6/20/2024
6.0.31878 146 6/19/2024
6.0.31877 99 6/19/2024
6.0.31876 101 6/19/2024
6.0.31875 105 6/19/2024
6.0.31874 96 6/19/2024
6.0.31873 95 6/19/2024
6.0.31872 108 6/19/2024
6.0.31871 95 6/19/2024
6.0.31870 99 6/19/2024
6.0.31869 93 6/19/2024
6.0.31868 107 6/18/2024
6.0.31867 92 6/18/2024
6.0.31866 106 6/18/2024
6.0.31865 104 6/18/2024
6.0.31864 103 6/18/2024
6.0.31863 93 6/18/2024
6.0.31862 101 6/18/2024
6.0.31861 91 6/18/2024
6.0.31860 98 6/17/2024
6.0.31859 98 6/17/2024
6.0.31858 95 6/17/2024
6.0.31857 97 6/17/2024
6.0.31856 104 6/17/2024
6.0.31855 95 6/17/2024
6.0.31854 95 6/17/2024
6.0.31853 103 6/17/2024
6.0.31852 102 6/17/2024
6.0.31851 101 6/17/2024
6.0.31850 99 6/17/2024
6.0.31849 94 6/17/2024
6.0.31848 99 6/15/2024
6.0.31847 97 6/15/2024
6.0.31846 88 6/14/2024
6.0.31845 103 6/14/2024
6.0.31844 102 6/14/2024
6.0.31843 91 6/14/2024
6.0.31842 98 6/14/2024
6.0.31841 96 6/13/2024
6.0.31840 102 6/13/2024
6.0.31839 99 6/13/2024
6.0.31838 93 6/13/2024
6.0.31837 97 6/13/2024
6.0.31836 97 6/13/2024
6.0.31835 97 6/13/2024
6.0.31834 91 6/13/2024
6.0.31833 83 6/12/2024
6.0.31832 80 6/12/2024
6.0.31831 79 6/11/2024
6.0.31830 78 6/11/2024
6.0.31829 77 6/11/2024
6.0.31828 79 6/11/2024
6.0.31827 82 6/11/2024
6.0.31826 77 6/11/2024
6.0.31825 86 6/10/2024
6.0.31824 78 6/10/2024
6.0.31823 80 6/10/2024
6.0.31822 81 6/10/2024
6.0.31821 80 6/10/2024
6.0.31820 83 6/10/2024
6.0.31819 82 6/10/2024
6.0.31818 77 6/10/2024
6.0.31817 83 6/7/2024
6.0.31816 84 6/7/2024
6.0.31815 89 6/7/2024
6.0.31814 93 6/6/2024
6.0.31813 91 6/6/2024
6.0.31812 96 6/6/2024
6.0.31811 90 6/6/2024
6.0.31810 95 6/6/2024
6.0.31809 94 6/6/2024
6.0.31808 91 6/6/2024
6.0.31807 92 6/5/2024
6.0.31806 101 6/4/2024
6.0.31805 94 6/4/2024
6.0.31804 92 6/4/2024
6.0.31803 94 6/4/2024
6.0.31802 94 6/4/2024
6.0.31801 97 6/3/2024
6.0.31800 93 6/3/2024
6.0.31799 84 6/3/2024
6.0.31798 86 6/3/2024
6.0.31797 77 6/3/2024
6.0.31796 92 6/3/2024
6.0.31795 100 6/3/2024
6.0.31794 110 5/31/2024
6.0.31793 109 5/30/2024
6.0.31792 102 5/30/2024
6.0.31791 99 5/30/2024
6.0.31790 96 5/30/2024
6.0.31789 97 5/30/2024
6.0.31788 101 5/30/2024
6.0.31787 102 5/29/2024
6.0.31786 94 5/29/2024
6.0.31785 98 5/29/2024
6.0.31784 89 5/29/2024
6.0.31783 110 5/27/2024
6.0.31782 93 5/27/2024
6.0.31781 104 5/26/2024
6.0.31780 98 5/24/2024
6.0.31779 100 5/22/2024
6.0.31778 107 5/22/2024
6.0.31777 94 5/22/2024
6.0.31776 100 5/22/2024
6.0.31775 99 5/22/2024
6.0.31774 91 5/21/2024
6.0.31773 91 5/21/2024
6.0.31772 102 5/20/2024
6.0.31771 95 5/16/2024
6.0.31770 89 5/15/2024
6.0.31769 96 5/15/2024
6.0.31768 100 5/15/2024
6.0.31767 84 5/15/2024
6.0.31766 100 5/15/2024
6.0.31764 92 5/14/2024
6.0.31763 87 5/14/2024
6.0.31762 84 5/14/2024
6.0.31761 93 5/14/2024
6.0.31760 94 5/14/2024
6.0.31759 99 5/13/2024
6.0.31758 96 5/13/2024
6.0.31757 85 5/13/2024
6.0.31756 89 5/12/2024
6.0.31755 91 5/12/2024
6.0.31754 97 5/12/2024
6.0.31753 101 5/8/2024
6.0.31751 105 5/7/2024
6.0.31749 104 5/6/2024
6.0.31748 110 5/6/2024
6.0.31747 114 5/6/2024
6.0.31746 73 5/3/2024
6.0.31745 60 5/3/2024
6.0.31744 62 5/3/2024
6.0.31743 61 5/2/2024
6.0.31742 104 4/27/2024
6.0.31741 102 4/27/2024
6.0.31740 104 4/26/2024
6.0.31739 98 4/26/2024
6.0.31738 112 4/26/2024
6.0.31737 112 4/26/2024
6.0.31735 126 4/25/2024
6.0.31734 99 4/25/2024
6.0.31733 99 4/25/2024
6.0.31732 102 4/25/2024
6.0.31731 90 4/25/2024
6.0.31730 107 4/24/2024
6.0.31729 98 4/24/2024
6.0.31728 103 4/24/2024
6.0.31727 100 4/23/2024
6.0.31726 86 4/23/2024
6.0.31725 101 4/23/2024
6.0.31724 102 4/22/2024
6.0.31723 102 4/22/2024
6.0.31722 109 4/22/2024
6.0.31721 108 4/22/2024
6.0.31720 101 4/22/2024
6.0.31719 99 4/22/2024
6.0.31718 102 4/22/2024
6.0.31717 103 4/22/2024
6.0.31716 100 4/22/2024
6.0.31715 114 4/20/2024
6.0.31714 113 4/19/2024
6.0.31713 91 4/19/2024
6.0.31712 89 4/19/2024
6.0.31711 105 4/19/2024
6.0.31710 92 4/19/2024
6.0.31709 99 4/19/2024
6.0.31708 100 4/18/2024
6.0.31707 95 4/18/2024
6.0.31706 93 4/18/2024
6.0.31705 92 4/17/2024
6.0.31704 111 4/17/2024
6.0.31703 99 4/17/2024
6.0.31702 101 4/17/2024
6.0.31701 97 4/16/2024
6.0.31700 94 4/16/2024
6.0.31699 96 4/16/2024
6.0.31698 89 4/16/2024
6.0.31697 90 4/16/2024
6.0.31696 88 4/16/2024
6.0.31695 86 4/16/2024
6.0.31694 93 4/16/2024
6.0.31693 92 4/16/2024
6.0.31692 89 4/15/2024
6.0.31691 90 4/15/2024
6.0.31690 102 4/15/2024
6.0.31688 109 4/12/2024
6.0.31687 89 4/12/2024
6.0.31686 91 4/12/2024
6.0.31685 90 4/12/2024
6.0.31684 89 4/11/2024
6.0.31683 99 4/10/2024
6.0.31682 90 4/10/2024
6.0.31681 90 4/10/2024
6.0.31680 95 4/10/2024
6.0.31679 86 4/10/2024
6.0.31678 86 4/10/2024
6.0.31677 100 4/9/2024
6.0.31676 105 4/9/2024
6.0.31675 101 4/8/2024
6.0.31674 108 4/8/2024
6.0.31673 108 4/8/2024
6.0.31672 86 4/8/2024
6.0.31671 86 4/8/2024
6.0.31670 96 4/8/2024
6.0.31669 94 4/8/2024
6.0.31668 102 4/5/2024
6.0.31667 104 4/5/2024
6.0.31666 110 4/3/2024
6.0.31665 101 4/3/2024
6.0.31663 106 4/3/2024
6.0.31662 97 4/3/2024
6.0.31661 102 4/2/2024
6.0.31660 105 4/1/2024
6.0.31659 95 4/1/2024
6.0.31658 92 4/1/2024
6.0.31657 96 3/29/2024
6.0.31656 90 3/29/2024
6.0.31655 93 3/29/2024
6.0.31654 101 3/29/2024
6.0.31653 86 3/29/2024
6.0.31651 83 3/29/2024
6.0.31650 88 3/29/2024
6.0.31649 89 3/29/2024
6.0.31648 89 3/29/2024
6.0.31647 87 3/29/2024
6.0.31646 109 3/29/2024
6.0.31645 92 3/28/2024
6.0.31644 94 3/28/2024
6.0.31643 100 3/28/2024
6.0.31642 95 3/28/2024
6.0.31639 99 3/28/2024
6.0.31638 84 3/28/2024
6.0.31637 108 3/27/2024
6.0.31636 130 3/27/2024
6.0.31631 98 3/27/2024
6.0.31626 105 3/26/2024
6.0.31625 111 3/25/2024
6.0.31618 109 3/20/2024
6.0.31617 100 3/20/2024
6.0.31616 111 3/20/2024
6.0.31615 99 3/20/2024
6.0.31614 119 3/19/2024
6.0.31613 114 3/18/2024
6.0.31612 124 3/18/2024
6.0.31611 124 3/18/2024
6.0.31610 118 3/18/2024
6.0.31609 113 3/15/2024
6.0.31608 113 3/14/2024
6.0.31607 125 3/13/2024
6.0.31606 113 3/13/2024
6.0.31605 111 3/13/2024
6.0.31604 109 3/12/2024
6.0.31603 108 3/12/2024
6.0.31602 139 3/7/2024
6.0.31601 122 3/7/2024
6.0.31600 124 3/7/2024
6.0.31599 120 3/6/2024
6.0.31598 110 3/6/2024
6.0.31597 114 3/6/2024
6.0.31596 111 3/6/2024
6.0.31595 125 3/6/2024
6.0.31594 113 3/4/2024
6.0.31593 103 3/4/2024
6.0.31590 111 3/1/2024
6.0.31589 108 3/1/2024
6.0.31588 109 3/1/2024
6.0.31587 101 3/1/2024
6.0.31586 109 3/1/2024
6.0.31585 102 3/1/2024
6.0.31584 110 3/1/2024
6.0.31583 102 3/1/2024
6.0.31582 109 2/29/2024
6.0.31581 99 2/29/2024
6.0.31580 107 2/29/2024
6.0.31579 111 2/29/2024
6.0.31578 110 2/29/2024
6.0.31577 106 2/29/2024
6.0.31576 111 2/29/2024
6.0.31575 110 2/28/2024