Merge pull request #108 from jrjrguo/issue-107
Enable setting custom test context parameters
This commit is contained in:
Коммит
8bedca24ea
|
@ -21,6 +21,7 @@
|
|||
// ***********************************************************************
|
||||
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Runner.Services;
|
||||
using NUnit.Runner.View;
|
||||
|
@ -59,9 +60,10 @@ namespace NUnit.Runner
|
|||
/// Adds an assembly to be tested.
|
||||
/// </summary>
|
||||
/// <param name="testAssembly">The test assembly.</param>
|
||||
public void AddTestAssembly(Assembly testAssembly)
|
||||
/// <param name="options">An optional dictionary of options for loading the assembly.</param>
|
||||
public void AddTestAssembly(Assembly testAssembly, Dictionary<string, object> options = null)
|
||||
{
|
||||
_model.AddTest(testAssembly);
|
||||
_model.AddTest(testAssembly, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -35,20 +35,20 @@ namespace NUnit.Runner.Helpers
|
|||
/// </summary>
|
||||
internal class TestPackage
|
||||
{
|
||||
private readonly List<Assembly> _testAssemblies = new List<Assembly>();
|
||||
private readonly List<(Assembly, Dictionary<string,object>)> _testAssemblies = new List<(Assembly, Dictionary<string,object>)>();
|
||||
|
||||
public void AddAssembly(Assembly testAssembly)
|
||||
public void AddAssembly(Assembly testAssembly, Dictionary<string,object> options = null)
|
||||
{
|
||||
_testAssemblies.Add(testAssembly);
|
||||
_testAssemblies.Add( (testAssembly, options) );
|
||||
}
|
||||
|
||||
public async Task<TestRunResult> ExecuteTests()
|
||||
{
|
||||
var resultPackage = new TestRunResult();
|
||||
|
||||
foreach (var assembly in _testAssemblies)
|
||||
foreach (var (assembly,options) in _testAssemblies)
|
||||
{
|
||||
NUnitTestAssemblyRunner runner = await LoadTestAssemblyAsync(assembly).ConfigureAwait(false);
|
||||
NUnitTestAssemblyRunner runner = await LoadTestAssemblyAsync(assembly, options).ConfigureAwait(false);
|
||||
ITestResult result = await Task.Run(() => runner.Run(TestListener.NULL, TestFilter.Empty)).ConfigureAwait(false);
|
||||
resultPackage.AddResult(result);
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ namespace NUnit.Runner.Helpers
|
|||
return resultPackage;
|
||||
}
|
||||
|
||||
private static async Task<NUnitTestAssemblyRunner> LoadTestAssemblyAsync(Assembly assembly)
|
||||
private static async Task<NUnitTestAssemblyRunner> LoadTestAssemblyAsync(Assembly assembly, Dictionary<string, object> options)
|
||||
{
|
||||
var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
|
||||
await Task.Run(() => runner.Load(assembly, new Dictionary<string, object>()));
|
||||
await Task.Run(() => runner.Load(assembly, options ?? new Dictionary<string, object>()));
|
||||
return runner;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
// ***********************************************************************
|
||||
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using NUnit.Runner.Helpers;
|
||||
|
@ -128,9 +129,9 @@ namespace NUnit.Runner.ViewModel
|
|||
/// </summary>
|
||||
/// <param name="testAssembly">The test assembly.</param>
|
||||
/// <returns></returns>
|
||||
internal void AddTest(Assembly testAssembly)
|
||||
internal void AddTest(Assembly testAssembly, Dictionary<string, object> options = null)
|
||||
{
|
||||
_testPackage.AddAssembly(testAssembly);
|
||||
_testPackage.AddAssembly(testAssembly, options);
|
||||
}
|
||||
|
||||
async Task ExecuteTestsAync()
|
||||
|
|
|
@ -44,6 +44,8 @@ namespace NUnit.Runner.Tests
|
|||
|
||||
// If you want to add tests in another assembly
|
||||
//nunit.AddTestAssembly(typeof(MyTests).Assembly);
|
||||
// Or, if you want to add tests with an extra test options dictionary
|
||||
//nunit.AddTestAssembly(typeof(MyTests).Assembly, new Dictionary<string, object>());
|
||||
|
||||
// Available options for testing
|
||||
nunit.Options = new TestOptions
|
||||
|
|
|
@ -53,6 +53,8 @@ namespace NUnit.Runner.Tests
|
|||
|
||||
// If you want to add tests in another assembly
|
||||
//nunit.AddTestAssembly(typeof(MyTests).Assembly);
|
||||
// Or, if you want to add tests with an extra test options dictionary
|
||||
//nunit.AddTestAssembly(typeof(MyTests).Assembly, new Dictionary<string, object>());
|
||||
|
||||
// Available options for testing
|
||||
nunit.Options = new TestOptions
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
// ***********************************************************************
|
||||
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Runner.Services;
|
||||
|
||||
|
@ -38,7 +39,11 @@ namespace NUnit.Runner.Tests
|
|||
|
||||
// If you want to add tests in another assembly, add a reference and
|
||||
// duplicate the following line with a type from the referenced assembly
|
||||
nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly);
|
||||
//nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly);
|
||||
// Or, if you want to add tests with an extra test options dictionary
|
||||
var parameters = new Dictionary<string, string> { { "Parameter", "Value" } };
|
||||
nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly,
|
||||
new Dictionary<string, object> { { FrameworkPackageSettings.TestParametersDictionary, parameters} });
|
||||
|
||||
// Available options for testing
|
||||
nunit.Options = new TestOptions
|
||||
|
|
|
@ -43,5 +43,13 @@ namespace NUnit.Runner.Tests
|
|||
{
|
||||
Assert.That(x + y, Is.EqualTo(expected));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPassedInParameter()
|
||||
{
|
||||
var val = TestContext.Parameters.Get("Parameter");
|
||||
TestContext.WriteLine("The passed-in value associated with 'Parameter' is: {0}", val?? "null");
|
||||
Assert.True(val == null || val == "Value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче