Exemplo n.º 1
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += ResolveDependentAssembly;

            // LoadFrom(@"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\TestPlatform");
            // LoadFrom(@"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Team Explorer");
            // LoadFrom(@"D:\Visual Studio 2015\Projects\BrowserTestAdapter\ConsoleApp1\bin\Debug\ForTest", SearchOption.TopDirectoryOnly);
            //LoadFrom(Environment.CurrentDirectory, SearchOption.AllDirectories);
            // test();
            //    AppDomain.CurrentDomain.AssemblyResolve += ResolveDependentAssembly;
            var ass      = Assembly.LoadFrom(@"D:\Visual Studio 2015\Projects\BrowserTestAdapter\ConsoleApp1\bin\Debug\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll");
            var type     = ass.GetType("Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.TrxLogger");
            var instance = Activator.CreateInstance(type);
            var method   = type.GetMethods().Where(m => m.Name == "Initialize").First();

            var ev = new MyEvents();

            method.Invoke(instance, new object[] { ev, @"D:\Visual Studio 2015\Projects\BrowserTestAdapter\ConsoleApp1\bin\Debug\Results" });

            ITestDiscoverer discoverer = new MSTestDiscoverer();
            string          folder     = @"D:\Visual Studio 2015\Projects\BrowserTestAdapter\Tests\bin\Debug";
            var             sources    = Directory.EnumerateFiles(folder).Where(file => Path.GetExtension(file) == ".dll").ToList();

            Environment.CurrentDirectory = @"D:\Visual Studio 2015\Projects\BrowserTestAdapter\ConsoleApp1\bin\Debug\ForTest";
            var fakeSink = new FakeTestCaseDiscoverySink();

            discoverer.DiscoverTests(sources, new FakeContext(), new FakeLogger(), fakeSink);
            Console.WriteLine("TEST CASES = " + fakeSink.testCases.Count);
            ITestExecutor executor = new MSTestExecutor();

            executor.RunTests(fakeSink.testCases, new FakeRunContext(), new FakeFrameworkHandle(ev));
            // ev.SendTestRunComplete(new List<AttachmentSet>());
        }
Exemplo n.º 2
0
        public async Task <List <TestCase> > LoadTests(string folder)
        {
            var task = Task.Run(() =>
            {
                ITestDiscoverer discoverer = new MSTestDiscoverer();
                var sources  = GetSources(folder, discoverer);
                var fakeSink = new FakeTestCaseDiscoverySink();
                discoverer.DiscoverTests(sources, new FakeContext(), new FakeLogger(), fakeSink);
                return(fakeSink.testCases);
            });

            return(await task);
        }
        private IEnumerable <TestCase> GetTests(string source)
        {
            var pluginPath = Path.GetDirectoryName(GetType().Assembly.Location);
            var sourcePath = Path.GetDirectoryName(source);
            var paths      = new[] { pluginPath, sourcePath };

            using (new AssemblyResolver(paths))
            {
                var sink       = new DiscoverySink();
                var discoverer = new MSTestDiscoverer();
                discoverer.DiscoverTests(source.ToEnumerable(), null, new NullLogger(), sink);
                return(sink.TestCases);
            }
        }