Ejemplo n.º 1
0
        /// <summary>
        /// Returns the VsTestConsole Wrapper.
        /// </summary>
        /// <returns></returns>
        public IVsTestConsoleWrapper GetVsTestConsoleWrapper()
        {
            var logFileName = Path.GetFileName(Path.GetTempFileName());
            var logFileDir  = Path.Combine(Path.GetTempPath(), "VSTestConsoleWrapperLogs");

            if (Directory.Exists(logFileDir) == false)
            {
                Directory.CreateDirectory(logFileDir);
            }

            var logFilePath = Path.Combine(logFileDir, logFileName);

            Console.WriteLine($"Logging diagnostics in {logFilePath}");

            string consoleRunnerPath;

            if (this.IsNetCoreRunner())
            {
                consoleRunnerPath = Path.Combine(this.testEnvironment.PublishDirectory, "vstest.console.dll");
            }
            else
            {
                consoleRunnerPath = this.GetConsoleRunnerPath();
            }

            var vstestConsoleWrapper = new VsTestConsoleWrapper(consoleRunnerPath, Path.Combine(this.testEnvironment.ToolsDirectory, @"dotnet\dotnet.exe"), new ConsoleParameters()
            {
                LogFilePath = logFilePath
            });

            vstestConsoleWrapper.StartSession();

            return(vstestConsoleWrapper);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the VsTestConsole Wrapper.
        /// </summary>
        /// <returns></returns>
        public IVsTestConsoleWrapper GetVsTestConsoleWrapper()
        {
            var vstestConsoleWrapper = new VsTestConsoleWrapper(this.GetConsoleRunnerPath());

            vstestConsoleWrapper.StartSession();

            return(vstestConsoleWrapper);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            // Spawn of vstest.console with a run tests from the current execting folder.
            var executingLocation = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            var runnerLocation    = Path.Combine(executingLocation, "vstest.console.exe");
            var testadapterPath   = Path.Combine(executingLocation, "Adapter\\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll");
            var testAssembly      = Path.Combine(executingLocation, "UnitTestProject.dll");

            IVsTestConsoleWrapper consoleWrapper = new VsTestConsoleWrapper(runnerLocation);

            consoleWrapper.StartSession();
            consoleWrapper.InitializeExtensions(new List <string>()
            {
                testadapterPath
            });

            var testCases = DiscoverTests(new List <string>()
            {
                testAssembly
            }, consoleWrapper);

            Console.WriteLine("Discovered Tests Count: " + testCases?.Count());
            Console.WriteLine("Discovered Test: " + testCases?.FirstOrDefault()?.DisplayName);

            Console.WriteLine("-------------------------------------------------------");

            var testresults = RunSelectedTests(consoleWrapper, testCases);

            Console.WriteLine("Run Selected Tests Count: " + testresults?.Count());
            Console.WriteLine("Run Selected Test Result: " + testresults?.FirstOrDefault()?.TestCase?.DisplayName + " :" + testresults?.FirstOrDefault()?.Outcome);

            Console.WriteLine("-------------------------------------------------------");

            testresults = RunAllTests(consoleWrapper, new List <string>()
            {
                testAssembly
            });

            Console.WriteLine("Run All Test Count: " + testresults?.Count());
            Console.WriteLine("Run All Test Result: " + testresults?.FirstOrDefault()?.TestCase?.DisplayName + " :" + testresults?.FirstOrDefault()?.Outcome);

            Console.WriteLine("-------------------------------------------------------");

            testresults = RunTestsWithCustomTestHostLauncher(consoleWrapper, new List <string>()
            {
                testAssembly
            });

            Console.WriteLine("Run All (custom launcher) Test Count: " + testresults?.Count());
            Console.WriteLine("Run All (custom launcher) Test Result: " + testresults?.FirstOrDefault()?.TestCase?.DisplayName + " :" + testresults?.FirstOrDefault()?.Outcome);

            Console.WriteLine("-------------------------------------------------------");
        }
Ejemplo n.º 4
0
        static async Task <int> MainAsync(string[] args)
        {
            if (args.Length != 1)
            {
                Console.Error.WriteLine("Usage: TestRunner.exe <path to assembly to be tested>");
                return(-1);
            }

            var pathToAssembly         = Path.GetFullPath(args[0]);
            var targetFrameworkVersion = GetTargetFrameworkVersion(pathToAssembly);

            Console.WriteLine("Will test assembly that targets {0}", targetFrameworkVersion);

            var pathToCurrentAssembly = Path.GetDirectoryName(new Uri(typeof(Program).Assembly.CodeBase).LocalPath);
            var pathToVSTest          = Path.GetFullPath(Path.Combine(pathToCurrentAssembly, "..", "TestPlatform", "Microsoft.TestPlatform.15.0.0", "tools", "net46", "vstest.console.exe"));

            if (!File.Exists(pathToVSTest))
            {
                Console.Error.WriteLine("Could not find vstest.console.exe. Make sure you have run build.cmd to restore it from NuGet.");
                return(-2);
            }

            var logFilePath = Path.Combine(pathToCurrentAssembly, "..", FormattableString.Invariant($"VSTest_{Path.GetFileName(pathToAssembly)}_{DateTime.Now:yyyyMMdd-HHmmss.fff}.log"));

            var console = new VsTestConsoleWrapper(pathToVSTest, new ConsoleParameters {
                LogFilePath = logFilePath
            });

            console.StartSession();

            var pathToAssemblyDirectory = Path.GetDirectoryName(pathToAssembly);
            var extensions = Directory.GetFiles(pathToAssemblyDirectory, "*.testadapter.dll", SearchOption.TopDirectoryOnly);

            foreach (var extension in extensions)
            {
                Console.WriteLine("Found extension {0}", Path.GetFileName(extension));
            }
            console.InitializeExtensions(extensions);

            var tests = await console.DiscoverTestsAsync(pathToAssembly, GetRunSettingsXml(targetFrameworkVersion)).ConfigureAwait(false);

            Console.WriteLine("Discovered {0} tests", tests.Count());
            foreach (var test in tests)
            {
                Console.WriteLine("  - {0}", test.FullyQualifiedName);
            }

            console.EndSession();
            return(0);
        }
Ejemplo n.º 5
0
        /**********************************************************************/
        #region Constructors

        public ExplorerVM()
        {
            _testPoints         = new ObservableCollection <ITestPointVM>();
            _readOnlyTestPoints = new ReadOnlyObservableCollection <ITestPointVM>(_testPoints);

            RunAllCommand  = new DelegateCommand(x => System.Windows.MessageBox.Show("TestVM.RunAllCommand.Execute()"));
            RefreshCommand = new DelegateCommand(x => DiscoverTests());

            _sources = new List <string>()
            {
                @"C:\Users\Jake\Documents\Visual Studio 2017\Projects\FaultDictionaryDebugger\CommonUtilitiesTests\bin\Debug\CommonUtilitiesTests.dll"
            };

            _adapters = new List <string>()
            {
                @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\NodejsTools\NodejsTools\Microsoft.NodejsTools.TestAdapter.dll",
                @"C:\Users\Jake\Documents\Visual Studio 2017\Projects\nunit3-vs-adapter\src\NUnitTestAdapter\bin\Debug\net35\NUnit3.TestAdapter.dll"
            };

            if (!Directory.Exists("log"))
            {
                Directory.CreateDirectory("log");
            }
            if (File.Exists("log\vstest.log"))
            {
                File.Delete("log\vstest.log");
            }

            _vstest = new VsTestConsoleWrapper(_vstestPath, new ConsoleParameters()
            {
                LogFilePath = @"log\vstest.log"
            });
            Task.Factory.StartNew(() =>
            {
                _vstest.StartSession();
                _vstest.InitializeExtensions(_adapters);
            }).ContinueWith(task =>
            {
                _vstestInitialized = (task.Status == TaskStatus.RanToCompletion);
            }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());

            _testDiscoveryManager = new TestDiscoveryManager(_vstest);
            _testDiscoveryManager.Sources.AddRange(_sources);
            _testDiscoveryManager.TestsAdded            += OnTestsDiscovered;
            _testDiscoveryManager.TestDiscoveryComplete += OnTestDiscoveryComplete;


            BreakCommand = new DelegateCommand(x => Break());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the VsTestConsole Wrapper.
        /// </summary>
        /// <returns></returns>
        public IVsTestConsoleWrapper GetVsTestConsoleWrapper()
        {
            var logFileName = Path.GetFileName(Path.GetTempFileName());
            var logFileDir  = Path.Combine(Path.GetTempPath(), "VSTestConsoleWrapperLogs");

            if (Directory.Exists(logFileDir) == false)
            {
                Directory.CreateDirectory(logFileDir);
            }

            var logFilePath = Path.Combine(logFileDir, logFileName);

            Console.WriteLine($"Logging diagnostics in {logFilePath}");

            string consoleRunnerPath;

            if (this.IsNetCoreRunner())
            {
                consoleRunnerPath = Path.Combine(this.testEnvironment.PublishDirectory, "vstest.console.dll");
            }
            else
            {
                consoleRunnerPath = this.GetConsoleRunnerPath();
            }
            var executablePath = IsWindows ? @"dotnet\dotnet.exe" : @"dotnet-linux/dotnet";
            var dotnetPath     = Path.Combine(this.testEnvironment.ToolsDirectory, executablePath);

            if (!File.Exists(dotnetPath))
            {
                throw new FileNotFoundException($"File '{dotnetPath}' was not found.");
            }

            var vstestConsoleWrapper = new VsTestConsoleWrapper(consoleRunnerPath, dotnetPath, new ConsoleParameters()
            {
                LogFilePath = logFilePath
            });

            vstestConsoleWrapper.StartSession();

            return(vstestConsoleWrapper);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            // Path to your test dll
            string testProject = @"C:\Projects\UnitTestProject1\bin\Debug\UnitTestProject1.dll";
            string runsettings = @"<?xml version=""1.0"" encoding=""utf-8""?>
                                             <RunSettings>
                                               <RunConfiguration>
                                               </RunConfiguration>
                                             </RunSettings>";

            VsTestConsoleWrapper wrapper = new VsTestConsoleWrapper(@"{path to your vstest.console.exe}");
            var handler = new RunEventsHandler();

            Console.WriteLine("Started");
            wrapper.StartSession();
            wrapper.RunTests(new List <string>()
            {
                testProject
            }, runsettings, handler);
            Console.WriteLine("Finished");
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        public static TestConsole Create(string pathToVSTest, string pathToAssemblyDirectory, bool debug)
        {
            var resolver          = ResolveAssemblies(pathToVSTest);
            var vstestConsolePath = Path.Combine(pathToVSTest, "vstest.console.exe");

            var parameters = new ConsoleParameters();

            if (debug)
            {
                parameters.LogFilePath = Path.Combine(Path.GetTempPath(), $"VSTestAdapter_{DateTime.Now:yyyyMMdd-HHmmss}.log");
            }

            var console = new VsTestConsoleWrapper(vstestConsolePath, parameters);

            console.StartSession();

            var extensions = Directory.GetFiles(pathToAssemblyDirectory, "*.testadapter.dll", SearchOption.TopDirectoryOnly);

            console.InitializeExtensions(extensions);

            return(new TestConsole(console, resolver));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the VsTestConsole Wrapper.
        /// </summary>
        /// <returns></returns>
        public IVsTestConsoleWrapper GetVsTestConsoleWrapper()
        {
            var logFileName = Path.GetFileName(Path.GetTempFileName());
            var logFileDir  = Path.Combine(Path.GetTempPath(), "VSTestConsoleWrapperLogs");

            if (Directory.Exists(logFileDir) == false)
            {
                Directory.CreateDirectory(logFileDir);
            }

            var logFilePath = Path.Combine(logFileDir, logFileName);

            Console.WriteLine($"Logging diagnostics in {logFilePath}");

            var vstestConsoleWrapper = new VsTestConsoleWrapper(this.GetConsoleRunnerPath(), new ConsoleParameters()
            {
                LogFilePath = logFilePath
            });

            vstestConsoleWrapper.StartSession();

            return(vstestConsoleWrapper);
        }
Ejemplo n.º 10
0
 public CLITestBase()
 {
     vsTestConsoleWrapper = new VsTestConsoleWrapper(this.GetConsoleRunnerPath());
     vsTestConsoleWrapper.StartSession();
 }
Ejemplo n.º 11
0
        public static int Main(string[] args)
        {
            if (args == null || args.Length < 1)
            {
                Console.WriteLine(@"Please provide appropriate arguments. Arguments can be passed as following:");
                Console.WriteLine(@"Microsoft.TestPlatform.TranslationLayer.E2ETest.exe --runner:'[vstest.console path]' --testassembly:'[assemblyPath]' --testadapterpath:'[path]'");
                Console.WriteLine(@"Example: Microsoft.TestPlatform.TranslationLayer.E2ETest.exe --runner:'c:\tmp\vstest.console.dll' --testassembly:'c:\a\a.tests.dll' --testadapterpath:'c:\a\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll'");

                return(1);
            }

            string runnerLocation  = string.Empty;
            string testadapterPath = string.Empty;
            string testAssembly    = string.Empty;

            var separator = new char[] { ':' };

            foreach (var arg in args)
            {
                if (arg.StartsWith("-p:") || arg.StartsWith("--testadapterpath:"))
                {
                    testadapterPath = arg.Split(separator, 2)[1];
                }
                else if (arg.StartsWith("-a:") || arg.StartsWith("--testassembly:"))
                {
                    testAssembly = arg.Split(separator, 2)[1];
                }
                else if (arg.StartsWith("-r:") || arg.StartsWith("--runner:"))
                {
                    runnerLocation = arg.Split(separator, 2)[1];
                }
            }

            Console.WriteLine("Parameters:");
            Console.WriteLine("Runner Path: " + runnerLocation);
            Console.WriteLine("Test Assembly Path: " + testAssembly);
            Console.WriteLine("Test Adapter Path: " + testadapterPath);
            Console.WriteLine("-------------------------------------------------------");

            var logFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"log.txt");
            IVsTestConsoleWrapper consoleWrapper = new VsTestConsoleWrapper(runnerLocation, new ConsoleParameters {
                LogFilePath = logFilePath
            });

            consoleWrapper.StartSession();
            consoleWrapper.InitializeExtensions(new List <string>()
            {
                testadapterPath
            });

            var testCases = DiscoverTests(new List <string>()
            {
                testAssembly
            }, consoleWrapper);

            Console.WriteLine("Discovered Tests Count: " + testCases?.Count());
            Console.WriteLine("Discovered Test: " + testCases?.FirstOrDefault()?.DisplayName);

            Console.WriteLine("-------------------------------------------------------");

            var testresults = RunSelectedTests(consoleWrapper, testCases);

            Console.WriteLine("Run Selected Tests Count: " + testresults?.Count());
            Console.WriteLine("Run Selected Test Result: " + testresults?.FirstOrDefault()?.TestCase?.DisplayName + " :" + testresults?.FirstOrDefault()?.Outcome);

            Console.WriteLine("-------------------------------------------------------");

            testresults = RunAllTests(consoleWrapper, new List <string>()
            {
                testAssembly
            });

            Console.WriteLine("Run All Test Count: " + testresults?.Count());
            Console.WriteLine("Run All Test Result: " + testresults?.FirstOrDefault()?.TestCase?.DisplayName + " :" + testresults?.FirstOrDefault()?.Outcome);

            Console.WriteLine("-------------------------------------------------------");

            testresults = RunTestsWithCustomTestHostLauncher(consoleWrapper, new List <string>()
            {
                testAssembly
            });

            Console.WriteLine("Run All (custom launcher) Test Count: " + testresults?.Count());
            Console.WriteLine("Run All (custom launcher) Test Result: " + testresults?.FirstOrDefault()?.TestCase?.DisplayName + " :" + testresults?.FirstOrDefault()?.Outcome);

            Console.WriteLine("-------------------------------------------------------");

            testresults = RunAllTestsWithTestCaseFilter(consoleWrapper, new List <string>()
            {
                testAssembly
            });

            Console.WriteLine("Run All Test Count: " + testresults?.Count());
            Console.WriteLine("Run All Test Result: " + testresults?.FirstOrDefault()?.TestCase?.DisplayName + " :" + testresults?.FirstOrDefault()?.Outcome);
            Console.WriteLine("-------------------------------------------------------");

            return(0);
        }