From 1a540081f97caf285ce7412080b20e461de88d0d Mon Sep 17 00:00:00 2001 From: Jiarui Guo Date: Thu, 28 Jun 2018 15:13:52 -0700 Subject: [PATCH 1/4] Support passing in test context parameters --- src/nunit.xamarin/App.xaml.cs | 4 ++-- src/nunit.xamarin/Helpers/TestPackage.cs | 14 +++++++------- src/nunit.xamarin/ViewModel/SummaryViewModel.cs | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/nunit.xamarin/App.xaml.cs b/src/nunit.xamarin/App.xaml.cs index 88ff613..db2e0fa 100644 --- a/src/nunit.xamarin/App.xaml.cs +++ b/src/nunit.xamarin/App.xaml.cs @@ -59,9 +59,9 @@ namespace NUnit.Runner /// Adds an assembly to be tested. /// /// The test assembly. - public void AddTestAssembly(Assembly testAssembly) + public void AddTestAssembly(Assembly testAssembly, Dictionary options = null) { - _model.AddTest(testAssembly); + _model.AddTest(testAssembly, options); } /// diff --git a/src/nunit.xamarin/Helpers/TestPackage.cs b/src/nunit.xamarin/Helpers/TestPackage.cs index ef86841..0e4fd0e 100644 --- a/src/nunit.xamarin/Helpers/TestPackage.cs +++ b/src/nunit.xamarin/Helpers/TestPackage.cs @@ -35,20 +35,20 @@ namespace NUnit.Runner.Helpers /// internal class TestPackage { - private readonly List _testAssemblies = new List(); + private readonly List<(Assembly, Dictionary)> _testAssemblies = new List<(Assembly, Dictionary)>(); - public void AddAssembly(Assembly testAssembly) + public void AddAssembly(Assembly testAssembly, Dictionary options = null) { - _testAssemblies.Add(testAssembly); + _testAssemblies.Add( (testAssembly, options) ); } public async Task 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 LoadTestAssemblyAsync(Assembly assembly) + private static async Task LoadTestAssemblyAsync(Assembly assembly, Dictionary options) { var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); - await Task.Run(() => runner.Load(assembly, new Dictionary())); + await Task.Run(() => runner.Load(assembly, options ?? new Dictionary())); return runner; } } diff --git a/src/nunit.xamarin/ViewModel/SummaryViewModel.cs b/src/nunit.xamarin/ViewModel/SummaryViewModel.cs index 3ffefec..e9f34af 100644 --- a/src/nunit.xamarin/ViewModel/SummaryViewModel.cs +++ b/src/nunit.xamarin/ViewModel/SummaryViewModel.cs @@ -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 /// /// The test assembly. /// - internal void AddTest(Assembly testAssembly) + internal void AddTest(Assembly testAssembly, Dictionary options = null) { - _testPackage.AddAssembly(testAssembly); + _testPackage.AddAssembly(testAssembly, options); } async Task ExecuteTestsAync() From f1c84977510a339d34221a3ad1fd9ac91b248dd8 Mon Sep 17 00:00:00 2001 From: Jiarui Guo Date: Thu, 28 Jun 2018 15:16:02 -0700 Subject: [PATCH 2/4] missing using namespace --- src/nunit.xamarin/App.xaml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nunit.xamarin/App.xaml.cs b/src/nunit.xamarin/App.xaml.cs index db2e0fa..571860a 100644 --- a/src/nunit.xamarin/App.xaml.cs +++ b/src/nunit.xamarin/App.xaml.cs @@ -21,6 +21,7 @@ // *********************************************************************** using System.Reflection; +using System.Collections.Generic; using NUnit.Runner.Services; using NUnit.Runner.View; From ed473d98aa4bdbf148db5b3f4129fc4fe20bda2c Mon Sep 17 00:00:00 2001 From: Jiarui Guo Date: Thu, 5 Jul 2018 14:16:30 -0700 Subject: [PATCH 3/4] Add comments, update tests --- src/nunit.xamarin/App.xaml.cs | 1 + tests/nunit.runner.tests.Droid/MainActivity.cs | 2 ++ tests/nunit.runner.tests.iOS/AppDelegate.cs | 2 ++ tests/nunit.runner.tests.uwp/MainPage.xaml.cs | 5 ++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nunit.xamarin/App.xaml.cs b/src/nunit.xamarin/App.xaml.cs index 571860a..cfba83e 100644 --- a/src/nunit.xamarin/App.xaml.cs +++ b/src/nunit.xamarin/App.xaml.cs @@ -60,6 +60,7 @@ namespace NUnit.Runner /// Adds an assembly to be tested. /// /// The test assembly. + /// An optional dictionary of options for loading the assembly. public void AddTestAssembly(Assembly testAssembly, Dictionary options = null) { _model.AddTest(testAssembly, options); diff --git a/tests/nunit.runner.tests.Droid/MainActivity.cs b/tests/nunit.runner.tests.Droid/MainActivity.cs index 7c8d4e1..b155c7b 100644 --- a/tests/nunit.runner.tests.Droid/MainActivity.cs +++ b/tests/nunit.runner.tests.Droid/MainActivity.cs @@ -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()); // Available options for testing nunit.Options = new TestOptions diff --git a/tests/nunit.runner.tests.iOS/AppDelegate.cs b/tests/nunit.runner.tests.iOS/AppDelegate.cs index bb0c697..53f2c87 100644 --- a/tests/nunit.runner.tests.iOS/AppDelegate.cs +++ b/tests/nunit.runner.tests.iOS/AppDelegate.cs @@ -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()); // Available options for testing nunit.Options = new TestOptions diff --git a/tests/nunit.runner.tests.uwp/MainPage.xaml.cs b/tests/nunit.runner.tests.uwp/MainPage.xaml.cs index 159a296..ee68e1d 100644 --- a/tests/nunit.runner.tests.uwp/MainPage.xaml.cs +++ b/tests/nunit.runner.tests.uwp/MainPage.xaml.cs @@ -21,6 +21,7 @@ // *********************************************************************** using System.Reflection; +using System.Collections.Generic; using NUnit.Runner.Services; @@ -38,7 +39,9 @@ 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 + nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly, new Dictionary()); // Available options for testing nunit.Options = new TestOptions From 0da5600d9866d4f880b5ec837c54419ace6d8337 Mon Sep 17 00:00:00 2001 From: Jiarui Guo Date: Mon, 10 Sep 2018 12:50:31 -0700 Subject: [PATCH 4/4] Extra test verifying passed in parameters --- tests/nunit.runner.tests.uwp/MainPage.xaml.cs | 4 +++- tests/nunit.runner.tests/TestCaseSample.cs | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/nunit.runner.tests.uwp/MainPage.xaml.cs b/tests/nunit.runner.tests.uwp/MainPage.xaml.cs index ee68e1d..15bf974 100644 --- a/tests/nunit.runner.tests.uwp/MainPage.xaml.cs +++ b/tests/nunit.runner.tests.uwp/MainPage.xaml.cs @@ -41,7 +41,9 @@ namespace NUnit.Runner.Tests // duplicate the following line with a type from the referenced assembly //nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly); // Or, if you want to add tests with an extra test options dictionary - nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly, new Dictionary()); + var parameters = new Dictionary { { "Parameter", "Value" } }; + nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly, + new Dictionary { { FrameworkPackageSettings.TestParametersDictionary, parameters} }); // Available options for testing nunit.Options = new TestOptions diff --git a/tests/nunit.runner.tests/TestCaseSample.cs b/tests/nunit.runner.tests/TestCaseSample.cs index 13e7c42..8f96a53 100644 --- a/tests/nunit.runner.tests/TestCaseSample.cs +++ b/tests/nunit.runner.tests/TestCaseSample.cs @@ -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"); + } +} }