Я пытаюсь запустить тесты в Xunit, используя сборщик сборок через код. Моя программа принимает имя файла dll, которое содержит набор тестов. Мне нужно запустить некоторые конкретные тесты из файла dll. Я не смотрю нареализация категории xunit. Нужно принять тестовый пример после завершения обнаружения.public List<ITestCase> TestCases { get; } = new List<ITestCase>();
введите код здесь
как добавить различные тестовые случаи в список.
Я надеюсь, что нам нужно выполнить фильтрацию после вызова
private void OnDiscoveryComplete(DiscoveryCompleteInfo info)
{
}
НоDiscoveryCompleteInfo содержит только значения int для TestCasesToRun и TestCasesDiscovered.
Как применить фильтр для тестов, чтобы тест выполнялся в соответствии с фильтром при вызове OnDiscoveryComplete.
public IList<TestResponse> ExecuteTest(string AutomationTestSuites)
{
try
{
_logger.LogInformation("Starting of the tests in {0} ", AutomationTestSuites);
IEnumerable<Assembly> assembly = GetReferencingAssemblies(AutomationTestSuites);
Assembly _assembly = assembly.Where(s => s.FullName.Contains(AutomationTestSuites)).FirstOrDefault();
using (var runner = AssemblyRunner.WithoutAppDomain(_assembly.Location))
{
runner.OnDiscoveryComplete = OnDiscoveryComplete;
runner.OnExecutionComplete = OnExecutionComplete;
runner.OnTestFailed = OnTestFailed;
runner.OnTestSkipped = OnTestSkipped;
runner.OnTestPassed = OnTestPassed;
_logger.LogInformation("Discovering Tests");
//Runs the Xunit runner in parallel if parallel is set to True
//If Max Parallel Threads is set to -1 there is no limit to number of threads for Xunit Runner
runner.Start(parallel: true, maxParallelThreads: -1);
finished.WaitOne();
finished.Dispose();
}
return (testResponses);
}
catch(Exception ex)
{
_logger.LogError("Exeption in ExecuteTestFunctionality : ", ex); return (testResponses);
}
}
public static IEnumerable<Assembly> GetReferencingAssemblies(string assemblyName)
{
var assemblies = new List<Assembly>();
var dependencies = DependencyContext.Default.RuntimeLibraries;
foreach (var library in dependencies)
{
if (IsCandidateLibrary(library, assemblyName))
{
var assembly = Assembly.Load(new AssemblyName(library.Name));
assemblies.Add(assembly);
}
}
return assemblies;
}
private static bool IsCandidateLibrary(RuntimeLibrary library, string assemblyName)
{
return library.Name == assemblyName
|| library.Dependencies.Any(d => d.Name.StartsWith(assemblyName));
}
private void OnDiscoveryComplete(DiscoveryCompleteInfo info)
{
_logger.LogInformation($"Running {info.TestCasesToRun} of {info.TestCasesDiscovered} tests...");
}
private void OnExecutionComplete(ExecutionCompleteInfo info)
{
_logger.LogInformation($"Finished: {info.TotalTests} tests in {Math.Round(info.ExecutionTime, executionTimeRoundOff)}s ({info.TestsFailed} failed, {info.TestsSkipped} skipped)");
finished.Set();
}
private void OnTestFailed(TestFailedInfo info)
{
_logger.LogError("Test [FAILED] {0}: {1}", info.TestDisplayName, info.ExceptionMessage);
}
private void OnTestPassed(TestPassedInfo info)
{
_logger.LogInformation("Test [Passed] : {0}", info.MethodName);
}
private void OnTestSkipped(TestSkippedInfo info)
{
_logger.LogWarning("Test [SKIPPED] {0}: {1}", info.MethodName,info.SkipReason);
}
потребностьотфильтровывать тестовые случаи из dll и запускать только выбранные тесты