Reo.Core.Xunit.IntegrationTesting 6.0.32000

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

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

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