Skip to content

CIパイプライン上のIntegrationTestでIConfigurationの差し替えが期待通り動作しない #909

@KentaHizume

Description

@KentaHizume

概要

CIパイプライン上のIntegrationTestの際には、IntegrationTestWebApplicationFactory.ConfigureWebHostでappsettings.IntegrationTest.jsonから結合テスト用DBの接続文字列の設定を行っている。

しかし、テストクラスからIConfigurationに設定された接続文字列を取得すると、
なぜかローカルDBの接続文字列となってしまっており、期待通り動作しない。

詳細 / 機能詳細(オプション)

現在はIntegrationTestWebApplicationFactoryにconnectionStringのフィールドを用意し、事前に接続文字列を格納しておき、テストクラスから使用することで暫定対処している。

    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
        var env = Environment.GetEnvironmentVariable("TEST_ENVIRONMENT") ?? Environments.Development;

        if (!env.Equals(Environments.Development, StringComparison.OrdinalIgnoreCase))
        {
            builder.ConfigureServices(services =>
            {
                var config = new ConfigurationBuilder()
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true)
                    .Build();

                services.AddDresscaEfInfrastructure(config);
                this.connectionString = config.GetConnectionString("DresscaDbContext");
            });
        }
    }

完了条件

  • 差し替えが期待通り動作しない原因を特定すること
  • connectionStringフィールドを使用するのではなく、IConfigurationServiceから接続文字列を取得してCIパイプライン上の結合テストが実行できること

Metadata

Metadata

Assignees

Labels

target: DresscaサンプルアプリケーションDresscaに関係がある

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions