From ef755ea6fb04b2675d91bc21b30cd3ddf07b37cc Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Fri, 25 Jan 2019 15:57:21 -0500 Subject: [PATCH] SPARK-1877: Test Runner for multiple test types --- .../spark_core/TestRunner/InProcessTestRunner.cs | 6 +++--- .../spark_core/TestRunner/TestEnumerator.cs | 16 ++++++++++++---- src/client/sparkcmd/Cmd/TestCommand.cs | 11 ++++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/client/spark_core/TestRunner/InProcessTestRunner.cs b/src/client/spark_core/TestRunner/InProcessTestRunner.cs index c64a580f5..9abf0f187 100644 --- a/src/client/spark_core/TestRunner/InProcessTestRunner.cs +++ b/src/client/spark_core/TestRunner/InProcessTestRunner.cs @@ -9,12 +9,12 @@ using System.Threading.Tasks; namespace bts.test { public static class InProcessTestRunner { - public static void run_test_syncronously(string v, TestEnumerator enumerator, Action report) { + public static void run_test_synchronously(string v, TestEnumerator enumerator, Action report) { foreach (var t in enumerator.find(v)) { - run_test_syncronously(t, report); + run_test_synchronously(t, report); } } - public static void run_test_syncronously(TestMethod test, Action report) { + public static void run_test_synchronously(TestMethod test, Action report) { var result = new TestResult() { TestName = test.full_name, Status = TestResult.Types.Step.Setup, diff --git a/src/client/spark_core/TestRunner/TestEnumerator.cs b/src/client/spark_core/TestRunner/TestEnumerator.cs index 2946b7ea0..36a402a03 100644 --- a/src/client/spark_core/TestRunner/TestEnumerator.cs +++ b/src/client/spark_core/TestRunner/TestEnumerator.cs @@ -7,23 +7,29 @@ namespace bts.test { public class TestEnumerator { public TestEnumerator(params string[] assemblies) { - TestGroups = + TestGroups = assemblies .Select(Assembly.Load) .SelectMany(a => a.GetTypes()) .Where(t => t.GetCustomAttribute() != null) .Select(t => - new TestClass(t, + new TestClass(t, + t.GetCustomAttribute().TestType, t.GetMethods() .Where(m => m.GetCustomAttribute() != null) .Select(m => new TestMethod(t, m)) .ToList())) - .ToList(); + .ToList(); } public IReadOnlyCollection TestGroups { get; } public IEnumerable Tests => TestGroups.SelectMany(t => t.methods); + public IEnumerable get_of_type(TestType tt) { + return TestGroups.Where(wt => wt.test_type == tt).SelectMany(t => t.methods); + } + + public IEnumerable find(string name) { foreach (var g in TestGroups) { foreach (var t in g.methods) { @@ -41,13 +47,15 @@ namespace bts.test { public class TestClass { - public TestClass(Type type, IEnumerable methods) { + public TestClass(Type type, TestType test_type, IEnumerable methods) { this.type = type; + this.test_type = test_type; this.methods = methods; } public string name => type.Name; public Assembly assembly => type.Assembly; public Type type { get; } + public TestType test_type { get; } public IEnumerable methods { get; } public override string ToString() { return $"[TestGroup:{name}]"; diff --git a/src/client/sparkcmd/Cmd/TestCommand.cs b/src/client/sparkcmd/Cmd/TestCommand.cs index 43bddadac..24343c289 100644 --- a/src/client/sparkcmd/Cmd/TestCommand.cs +++ b/src/client/sparkcmd/Cmd/TestCommand.cs @@ -15,12 +15,17 @@ namespace sparkcmd { uint _parallel = 1; bool _list; + TestType test_type = TestType.Unit; + public TestCommand() { IsCommand("test", "Run managed unit tests"); - // i comes thorugh as "t" which seems daft. + // i comes thorugh as "t" which seems daft. HasOption("t|timeout", "Timeout unit tests", i => _timeout = 10); HasOption("n|parallel", "How many tests to run in parallel", i => _parallel = i); HasOption("l|list", "List all tests", _ => _list = true); + HasOption("unit","Run unit tests", _ => test_type = TestType.Unit); + HasOption("system","Run system tests", _ => test_type = TestType.System); + HasOption("shell","Run shell tests", _ => test_type = TestType.Shell); HasAdditionalArguments(null, " [Test List]"); } @@ -35,7 +40,7 @@ namespace sparkcmd { if (_timeout == 0 && tests.Length == 1) { //System.Threading.Thread.Sleep(5000); using (var trr = new TestResultReceiver(true)) { - InProcessTestRunner.run_test_syncronously(tests[0], Enumerator, trr.get_reporter()); + InProcessTestRunner.run_test_synchronously(tests[0], Enumerator, trr.get_reporter()); trr.print_summary(); return trr.ErrorCount; } @@ -44,7 +49,7 @@ namespace sparkcmd { return run_tests(Enumerator.match(tests).Select(t => t.name)); } else { - return run_tests(Enumerator.Tests.Select(t => t.full_name)); + return run_tests(Enumerator.get_of_type(test_type).Select(t => t.full_name)); } }