Пример #1
0
        private static void SetEnableCommandDataOption([NotNull] TestRunOptions options, bool enableCommandData)
        {
            options.MaxParallelThreads = enableCommandData ? 1 : (int?)null;

            options.NoAppDomain = enableCommandData;

            options.ParallelizeAssemblies = enableCommandData ? false : (bool?)null;

            options.ParallelizeTestCollections = enableCommandData ? false : (bool?)null;
        }
Пример #2
0
 internal RunMCutTestCaseCommand(MCutTestEntity test, MCutTestRunType runType, TestContextEntityBase context, TestArgs args, RunMCutTestOptions runOptions, bool interactive)
     : base(interactive)
 {
     _runOptions     = runOptions;
     _createTaskFunc = () => {
         var task = (RunMCutTestCaseAppTask)test.CreateRunTestTask(runType);
         task.ParentEntity = test;
         task.TestContext  = context;
         task.TestArgs     = args;
         return(task);
     };
 }
Пример #3
0
 internal RunMCutTestCaseCommand(MCutTestCaseRunEntity prevTestRun, MCutTestRunType runType, RunMCutTestOptions runOptions, bool interactive)
     : base(interactive)
     //: this(testRun.OwningTest
     //, testRun.DataElement.Element(XTestResultNames.TestResult)
     //, testRun.OwningTest.CreateXTestCase(testRun.TestCase, prototype)
     //, prototype, interactive)
 {
     _runOptions     = runOptions;
     _createTaskFunc = () => {
         var task = (RunMCutTestCaseAppTask)prevTestRun.OwningTest.CreateRunTestTask(runType);
         task.ParentEntity = prevTestRun.Result;
         task.PreviousRun  = prevTestRun;
         return(task);
     };
 }
Пример #4
0
        public override bool Execute()
        {
            // There's nothing to do if we have no source files
            if (String.IsNullOrEmpty(XapFile))
            {
                return(true);
            }

            if (String.IsNullOrEmpty(ApplicationProductId) && !String.IsNullOrEmpty(ApplicationManifest))
            {
                ApplicationProductId = GetApplicationProductId();

                if (!String.IsNullOrEmpty(ApplicationProductId))
                {
                    Log.LogMessage("ProductId extracted from manifest: {0}", ApplicationProductId);
                }
            }

            if (String.IsNullOrEmpty(ApplicationProductId))
            {
                Log.LogError("ApplicationProductId was not supplied and could not be found");
                return(false);
            }

            // Process the files
            bool succeeded = true;

            try
            {
                string   testPath        = XapFile;
                FileInfo testApplication = new FileInfo(testPath);

                // Make sure they didn't pass a directory as an item
                if (Directory.Exists(testPath))
                {
                    Log.LogError("Cannot move item {0} because it is a directory!", testPath);
                    return(false);
                }

                // Make sure the source exists
                if (!testApplication.Exists)
                {
                    Log.LogError("Cannot process file {0} that does not exist!", testPath);
                    return(false);
                }

                string testName = GetTestName(testApplication.Directory);
                if (!string.IsNullOrEmpty(TagExpression))
                {
                    testName += " (" + TagExpression + ")";
                }

                string name = TestResultsFile;
                if (string.IsNullOrEmpty(name))
                {
                    int k = 1;
                    name = "TestResults.trx";
                    while (File.Exists(Path.Combine(testApplication.DirectoryName, name)))
                    {
                        name = string.Format(CultureInfo.InvariantCulture, "TestResults{0}.trx", k++);
                    }
                }
                FileInfo log = new FileInfo(Path.Combine(testApplication.DirectoryName, name));

                Log.LogMessage("Begin unit testing");

                TestRunOptions tro = new TestRunOptions
                {
                    XapFile = testApplication.FullName,
                    ApplicationProductId = new Guid(ApplicationProductId),
                    UpdateApplication    = UpdateApplication,
                    DeviceInfo           = CreateDeviceInfo(),
                    TagExpression        = TagExpression,
                    Log       = log.FullName,
                    LocalPath = Path.GetDirectoryName(log.FullName)
                };
                tro.Page = testApplication.Name;

                TestRun tr = new TestRun(
                    new TestServiceOptions(),
                    tro);
                tr.Run();

                // Interpret results
                string pass  = null;
                string total = null;

                if (log.Exists)
                {
                    DisplayTestResults(log, ref total, ref pass);

                    if (DeleteLogFiles)
                    {
                        log.Delete();
                    }
                }
                else
                {
                    Log.LogError(
                        "The log file {0} was never written by the test service for the {1} test.",
                        log.FullName,
                        testName);
                }

                if (tr.Total == 0)
                {
                    Log.LogWarning(
                        "There were 0 reported scenarios executed. Check that the tag expression is appropriate.");
                }
                else if (tr.Failures == 0)
                {
                    Log.LogMessage(
                        MessageImportance.High,
                        "Unit tests ({0}): {1}{2}",
                        testName,
                        pass != null ? " " + pass + " passing tests" : "",
                        total != null ? " " + total + " total tests" : "");
                }
                else
                {
                    succeeded = false;
                    LogFailureMessage(
                        "Unit test failures in test " +
                        testName +
                        ", " +
                        tr.Failures.ToString(CultureInfo.CurrentUICulture) +
                        " failed scenarios out of " +
                        tr.Total.ToString(CultureInfo.CurrentUICulture) +
                        " total scenarios executed.");
                }
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
                succeeded = false;
            }

            return(succeeded);
        }
Пример #5
0
        /// <inheritdoc />
        public Result Execute([NotNull] ExternalCommandData commandData, [CanBeNull] ref string message, [CanBeNull][ItemNotNull] ElementSet elements)
        {
            try
            {
                CommandData = commandData ?? throw new ArgumentNullException(nameof(commandData));

                var testRunnerControlViewModel = new TestRunnerControlViewModel(DispatcherScheduler.Current);

                var mainWindowHandlePtr = Process.GetCurrentProcess().MainWindowHandle;

                var testRunnerWindow = new TestRunnerWindow
                {
                    DataContext           = testRunnerControlViewModel,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };

                // ReSharper disable once UnusedVariable
                var wih = new WindowInteropHelper(testRunnerWindow)
                {
                    Owner = mainWindowHandlePtr
                };

                if (testRunnerWindow.ShowDialog() != true)
                {
                    return(Result.Cancelled);
                }

                var selectedAssemblyList = testRunnerControlViewModel.SelectedAssemblies.ToList();

                if (!selectedAssemblyList.Any())
                {
                    TaskDialog.Show("Error", "No assemblies selected");
                    return(Result.Failed);
                }

                var nonExistentAssemblies = selectedAssemblyList.Where(a => !File.Exists(a)).ToList();

                if (nonExistentAssemblies.Any())
                {
                    TaskDialog.Show("Error", $"One or more assemblies does not exist: {nonExistentAssemblies.JoinList(", ")}");
                    return(Result.Failed);
                }

                List <string> assemblyList = BuildAssemblyList(testRunnerControlViewModel);

                var stopWatch = Stopwatch.StartNew();

                var logger     = new RvtRunnerLogger(stopWatch);
                var testRunner = new TestRunner(logger);

                var reporter = new DefaultRunnerReporterWithTypes();

                var options = new TestRunOptions(assemblyList, reporter);

                SetEnableCommandDataOption(options, testRunnerControlViewModel.AllowCommandDataAccess);

                var result = testRunner.Run(options);

                stopWatch.Stop();

                var allMessages = logger.AllMessages.JoinList();

                new TaskDialog("Result")
                {
                    MainInstruction = $"Failing tests: {result}. Total time elapsed: {stopWatch.Elapsed}",
                    ExpandedContent = allMessages
                }.Show();

                Debug.WriteLine(result);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", $"{ex.GetType()} - {ex.Message}");
                return(Result.Failed);
            }
            finally
            {
                CommandData = null;
            }

            return(Result.Succeeded);
        }
Пример #6
0
        public override bool Execute()
        {
            // There's nothing to do if we have no source files
            if (TestPages == null || TestPages.Length == 0)
            {
                return(true);
            }

            // Process the files
            bool succeeded = true;

            try
            {
                for (int i = 0; i < TestPages.Length; i++)
                {
                    string   testPath        = TestPages[i].ItemSpec;
                    FileInfo testApplication = new FileInfo(testPath);

                    // Make sure they didn't pass a directory as an item
                    if (Directory.Exists(testPath))
                    {
                        Log.LogError("Cannot move item {0} because it is a directory!", testPath);
                        succeeded = false;
                        continue;
                    }

                    // Make sure the source exists
                    if (!testApplication.Exists)
                    {
                        Log.LogError("Cannot process file {0} that does not exist!", testPath);
                        succeeded = false;
                        continue;
                    }

                    string testName = GetTestName(testApplication.Directory);
                    if (!string.IsNullOrEmpty(TagExpression))
                    {
                        testName += " (" + TagExpression + ")";
                    }

                    string name = TestResultsFile;
                    if (string.IsNullOrEmpty(name))
                    {
                        int k = 1;
                        name = "TestResults.trx";
                        while (File.Exists(Path.Combine(testApplication.DirectoryName, name)))
                        {
                            name = string.Format(CultureInfo.InvariantCulture, "TestResults{0}.trx", k++);
                        }
                    }
                    FileInfo log = new FileInfo(Path.Combine(testApplication.DirectoryName, name));

                    WebBrowserBrand wbb = WebBrowserFactory.ParseBrand(Browser);
                    TestRunOptions  tro = new TestRunOptions
                    {
                        // StartupUri = testApplication.Name,
                        Browser       = wbb,
                        LocalPath     = testApplication.DirectoryName,
                        TagExpression = TagExpression,
                    };
                    tro.Page = testApplication.Name;
                    tro.Log  = log.FullName;

                    if (wbb == WebBrowserBrand.Custom)
                    {
                        tro.SetCustomBrowser(Browser);
                    }
                    TestRun tr = new TestRun(
                        new TestServiceOptions(),
                        tro);
                    tr.Run();

                    // Interpret results
                    string pass  = null;
                    string total = null;

                    if (log.Exists)
                    {
                        DisplayTestResults(log, ref total, ref pass);

                        if (DeleteLogFiles)
                        {
                            log.Delete();
                        }
                    }
                    else
                    {
                        Log.LogWarning(
                            "The log file {0} was never written by the test service for the {1} test.",
                            log.FullName,
                            testName);
                    }

                    if (tr.Total == 0)
                    {
                        Log.LogWarning("There were 0 reported scenarios executed. Check that the tag expression is appropriate.");
                    }
                    else if (tr.Failures == 0)
                    {
                        Log.LogMessage(
                            MessageImportance.High,
                            "Unit tests ({0}): {1}{2}",
                            testName,
                            pass != null ? " " + pass + " passing tests" : "",
                            total != null ? " " + total + " total tests" : "");
                    }
                    else
                    {
                        succeeded = false;
                        LogFailureMessage(
                            "Unit test failures in test " +
                            testName +
                            ", " +
                            tr.Failures.ToString(CultureInfo.CurrentUICulture) +
                            " failed scenarios out of " +
                            tr.Total.ToString(CultureInfo.CurrentUICulture) +
                            " total scenarios executed.");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
                succeeded = false;
            }

            return(succeeded);
        }