Test driver improvements (#117)

* Refactored the test driver to work with xunit in addition to the command line

* Fix behavior of property
This commit is contained in:
Mitchell Sternke
2016-10-25 17:16:33 -07:00
committed by GitHub
parent cac3ae5eeb
commit 67d1d800a3
9 changed files with 241 additions and 66 deletions

View File

@@ -4,10 +4,10 @@
//
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Driver;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.TestDriver
{
@@ -17,48 +17,37 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver
{
if (args.Length < 1)
{
Console.WriteLine( "Microsoft.SqlTools.ServiceLayer.TestDriver.exe <service host executable> [tests]" + Environment.NewLine +
" <service host executable> is the path to the Microsoft.SqlTools.ServiceLayer.exe executable" + Environment.NewLine +
Console.WriteLine( "Microsoft.SqlTools.ServiceLayer.TestDriver.exe [tests]" + Environment.NewLine +
" [tests] is a space-separated list of tests to run." + Environment.NewLine +
" They are qualified within the Microsoft.SqlTools.ServiceLayer.TestDriver.Tests namespace");
" They are qualified within the Microsoft.SqlTools.ServiceLayer.TestDriver.Tests namespace" + Environment.NewLine +
"Be sure to set the environment variable " + ServiceTestDriver.ServiceHostEnvironmentVariable + " to the full path of the sqltoolsservice executable.");
Environment.Exit(0);
}
Logger.Initialize("testdriver", LogLevel.Verbose);
Task.Run(async () =>
{
var serviceHostExecutable = args[0];
var tests = args.Skip(1);
foreach (var test in tests)
foreach (var test in args)
{
ServiceTestDriver driver = null;
try
{
driver = new ServiceTestDriver(serviceHostExecutable);
var className = test.Substring(0, test.LastIndexOf('.'));
var methodName = test.Substring(test.LastIndexOf('.') + 1);
var type = Type.GetType("Microsoft.SqlTools.ServiceLayer.TestDriver.Tests." + className);
var typeInstance = Activator.CreateInstance(type);
MethodInfo methodInfo = type.GetMethod(methodName);
using (var typeInstance = (IDisposable)Activator.CreateInstance(type))
{
MethodInfo methodInfo = type.GetMethod(methodName);
await driver.Start();
Console.WriteLine("Running test " + test);
await (Task)methodInfo.Invoke(typeInstance, new object[] {driver});
Console.WriteLine("Running test " + test);
await (Task)methodInfo.Invoke(typeInstance, null);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
if (driver != null)
{
await driver.Stop();
}
}
}
}).Wait();
}