public void Run(XunitTestAssemblyTask assemblyTask, TaskProvider taskProvider) { var priorCurrentDirectory = Environment.CurrentDirectory; try { // Use the assembly in the folder that the user has specified, or, if not, use the assembly location var assemblyFolder = GetAssemblyFolder(configuration, assemblyTask); var assemblyPath = Path.Combine(assemblyFolder, GetFileName(assemblyTask.AssemblyLocation)); Environment.CurrentDirectory = assemblyFolder; // If we just pass null for the config file, the AppDomain will load {assembly}.config if it exists, // or use the config file of this app domain, which will usually be JetBrains.ReSharper.TaskRunner.*.exe.config. // If we specify the name directly, it will just use it, or have no configuration, with no fallback. // This is good because it stops the TaskRunner.exe config leaking into your tests. For example, that // file redirects all ReSharper assemblies to the current version. When the default AppDomain loads our // code, the assemblies are successfully redirected, and we use the latest version. If the new AppDomain // uses the same redirects, and the test assembly references resharper assemblies (e.g. xunitcontrib tests!) // the redirects are applied, but the new AppDomain can't find the newer assemblies, and throws var configFile = assemblyPath + ".config"; using (var executorWrapper = new ExecutorWrapper(assemblyPath, configFile, configuration.ShadowCopy)) { SetTempFolderPath(executorWrapper); var run = new XunitTestRun(server, executorWrapper, taskProvider); run.RunTests(); } } finally { Environment.CurrentDirectory = priorCurrentDirectory; } }
private void ReportException(XunitTestAssemblyTask assemblyTask, TestEnvironment environment, Exception e) { Logger.LogException(e); var description = "Exception: " + e; if (environment.DiagnosticMessages != null && environment.DiagnosticMessages.HasMessages) { description = string.Format("{0}{1}{1}Diagnostic Messages:{1}{2}", description, Environment.NewLine, environment.DiagnosticMessages.Messages); } server.ShowNotification("Unable to run xUnit.net tests - " + e.Message, description); // This doesn't help - assemblyTask doesn't map to anything in the tree... server.TaskException(assemblyTask, new[] { new TaskException(e) }); }
public TestEnvironment(XunitTestAssemblyTask assemblyTask, bool disableAllConcurrency) { // Use the assembly in the folder that the user has specified, or, if not, use the assembly location var assemblyFolder = GetAssemblyFolder(ResharperConfiguration, assemblyTask); AssemblyPath = Path.Combine(assemblyFolder, Path.GetFileName(assemblyTask.AssemblyLocation)); ConfigPath = GetConfigFile(AssemblyPath); Logger.LogVerbose("Setting current directory to {0}", assemblyFolder); Environment.CurrentDirectory = assemblyFolder; // Tell ReSharper about the shadow copy path, so it can clean up after abort. Xunit (1+2) will try and // clean up at the end of the run ShadowCopyPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); // The hosts require disabling concurrency (e.g. code coverage, continuous testing, dotMemoryUnit) DisableAllConcurrency = disableAllConcurrency; TestAssemblyConfiguration = GetXunitConfiguration(AssemblyPath, ConfigPath); MergeConfiguration(); DiagnosticMessages = new DiagnosticMessages(TestAssemblyConfiguration.DiagnosticMessagesOrDefault); }
public void Run(XunitTestAssemblyTask assemblyTask, bool disableAllConcurrency) { var environment = new TestEnvironment(assemblyTask, disableAllConcurrency); try { if (environment.TestAssemblyConfiguration.ShadowCopyOrDefault) { server.SetTempFolderPath(environment.ShadowCopyPath); } using (var controller = GetFrontController(environment)) { var discoverer = new Discoverer(controller, RunContext, environment); var testCases = discoverer.GetTestCases(); if (testCases.Count == 0) { throw new InternalErrorException("Unexpected: Unable to find any matching test cases"); } if (testCases.Count > 0) { RunContext.AddRange(testCases); var executor = new Executor(controller, RunContext, environment); executor.RunTests(testCases); } } environment.DiagnosticMessages.Report(server); } catch (Exception e) { ReportException(assemblyTask, environment, e); } }
private static string GetAssemblyFolder(TaskExecutorConfiguration config, XunitTestAssemblyTask assemblyTask) { return(string.IsNullOrEmpty(config.AssemblyFolder) ? GetDirectoryName(assemblyTask.AssemblyLocation) : config.AssemblyFolder); }