SPARK-1877: Test Runner for multiple test types

This commit is contained in:
Michael Harding committed 2019-01-25 15:57:21 -05:00
1 parent 111767522f
commit ef755ea6fb
3 files changed
+23 -10

No files matched your search

@@ -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<TestResult> report) {
public static void run_test_synchronously(string v, TestEnumerator enumerator, Action<TestResult> 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<TestResult> report) {
public static void run_test_synchronously(TestMethod test, Action<TestResult> report) {
var result = new TestResult() {
TestName = test.full_name,
Status = TestResult.Types.Step.Setup,
@@ -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<TestGroupAttribute>() != null)
.Select(t =>
new TestClass(t,
new TestClass(t,
t.GetCustomAttribute<TestGroupAttribute>().TestType,
t.GetMethods()
.Where(m => m.GetCustomAttribute<TestAttribute>() != null)
.Select(m => new TestMethod(t, m))
.ToList()))
.ToList();
.ToList();
}
public IReadOnlyCollection<TestClass> TestGroups { get; }
public IEnumerable<TestMethod> Tests => TestGroups.SelectMany(t => t.methods);
public IEnumerable<TestMethod> get_of_type(TestType tt) {
return TestGroups.Where(wt => wt.test_type == tt).SelectMany(t => t.methods);
}
public IEnumerable<TestMethod> 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<TestMethod> methods) {
public TestClass(Type type, TestType test_type, IEnumerable<TestMethod> 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<TestMethod> methods { get; }
public override string ToString() {
return $"[TestGroup:{name}]";
+8 -3
View File
@@ -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<uint>("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));
}
}