Führen Sie Xunit -Tests in Theorie nacheinander aus (nicht parallel)C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Führen Sie Xunit -Tests in Theorie nacheinander aus (nicht parallel)

Post by Anonymous »

Wir hosten Konfigurationsdateien für verschiedene Umgebungen in unserem Git -Repo. Als Teil des CI -Prozesses würde ich gerne machen, dass diese Konfigurationsdateien immer gültig sind. Dazu habe ich diesen Test erstellt, der die Konfigurationen kopiert, versucht, den Server zu starten und ihn sofort abzuschließen. < /P>

Code: Select all

public class DeployConfigurationValidationTests
{
#region Private Fields

private readonly ITestOutputHelper _testOutputHelper;
private const string ServerBaseUrl = "http://localhost:44315";

#endregion

#region Constructors

public DeployConfigurationValidationTests(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

#endregion

#region Public Tests

/// 
/// Copies all files contained in the directory specified by parameter  to the executing directory and launches the application with this configuration.
/// 
/// The path of the directory containing the deploy configurations
[Theory]
[InlineData("../../../../../Configurations/Dev/")]
[InlineData("../../../../../Configurations/Int/")]
[InlineData("../../../../../Configurations/Prod/")]
public async Task ValidateDeployConfigurationsTest(string deployConfigDirectoryPath)
{
// Arrange (copy deploy configurations into directory where the test is running)
var currentDirectory = Directory.GetCurrentDirectory();
var configurationFilePaths = Directory.GetFiles(deployConfigDirectoryPath);
foreach (var configurationFilePath in configurationFilePaths)
{
var configurationFileName = Path.GetFileName(configurationFilePath);
var destinationFilePath = Path.Combine(currentDirectory, configurationFileName);
File.Copy(configurationFilePath, Path.Combine(currentDirectory, destinationFilePath), true);
_testOutputHelper.WriteLine($"Copied file '{Path.GetFullPath(configurationFilePath)}' to '{destinationFilePath}'");
}

// Act (launch the application with the deploy config)
var hostBuilder = Program.CreateHostBuilder(null)
.ConfigureWebHostDefaults(webHostBuilder =>
{
webHostBuilder.UseUrls(ServerBaseUrl);
webHostBuilder.UseTestServer();
});

using var host = await hostBuilder.StartAsync();

// Assert
// Nothing to assert, if no error occurs, the config is fine
}

#endregion
}
Der Test funktioniert gut, wenn jedes inlinedata einzeln ausgeführt wird, fällt jedoch beim Ausführen der Theorie fehl, da die Tests standardmäßig parallel durchgeführt werden. Es wird offensichtlich nicht funktionieren, mehrere (Test-) Server auf demselben Port mit denselben DLLs zu starten.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post