Example #1
0
        /// <summary>
        /// Starts running tests from a single type (if provided) or the whole assembly (if not). This call returns
        /// immediately, and status results are dispatched to the Info>s on this class. Callers can check <see cref="Status"/>
        /// to find out the current status.
        /// </summary>
        /// <param name="typeName">The (optional) type name of the single test class to run</param>
        /// <param name="diagnosticMessages">Set to <c>true</c> to enable diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        /// <param name="methodDisplay">Set to choose the default display name style for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="methodDisplayOptions">Set to choose the default display name style options for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="preEnumerateTheories">Set to <c>true</c> to pre-enumerate individual theory tests; set to <c>false</c> to use
        /// a single test case for the theory. By default, uses the value from the assembly configuration file. (This parameter is ignored
        /// for xUnit.net v1 tests.)</param>
        /// <param name="parallel">Set to <c>true</c> to run test collections in parallel; set to <c>false</c> to run them sequentially.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="maxParallelThreads">Set to 0 to use unlimited threads; set to any other positive integer to limit to an exact number
        /// of threads. By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="internalDiagnosticMessages">Set to <c>true</c> to enable internal diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        public void Discover(
            string typeName                 = null,
            bool?diagnosticMessages         = null,
            TestMethodDisplay?methodDisplay = null,
            TestMethodDisplayOptions?methodDisplayOptions = null,
            bool?preEnumerateTheories       = null,
            bool?internalDiagnosticMessages = null)
        {
            cancelled           = false;
            testCasesDiscovered = 0;
            testCasesToRun.Clear();

            XunitWorkerThread.QueueUserWorkItem(() =>
            {
                var discoveryOptions = GetDiscoveryOptions(diagnosticMessages, methodDisplay, methodDisplayOptions, preEnumerateTheories, internalDiagnosticMessages);
                if (typeName != null)
                {
                    controller.Find(typeName, false, this, discoveryOptions);
                }
                else
                {
                    controller.Find(false, this, discoveryOptions);
                }

                if (cancelled)
                {
                    // Synthesize the execution complete message, since we're not going to run at all
                    if (OnExecutionComplete != null)
                    {
                        OnExecutionComplete(ExecutionCompleteInfo.Empty);
                    }
                    return;
                }
            });
        }
Example #2
0
        public void Run(List <ITestCase> cases,
                        bool?diagnosticMessages         = null,
                        bool?parallel                   = null,
                        int?maxParallelThreads          = null,
                        bool?internalDiagnosticMessages = null)
        {
            cancelled           = false;
            testCasesDiscovered = cases.Count();
            testCasesToRun.Clear();
            testCasesToRun.AddRange(cases);

            XunitWorkerThread.QueueUserWorkItem(() =>
            {
                if (cancelled)
                {
                    // Synthesize the execution complete message, since we're not going to run at all
                    if (OnExecutionComplete != null)
                    {
                        OnExecutionComplete(ExecutionCompleteInfo.Empty);
                    }
                    return;
                }

                var executionOptions = GetExecutionOptions(diagnosticMessages, parallel, maxParallelThreads, internalDiagnosticMessages);

                controller.RunTests(testCasesToRun, this, executionOptions);
            });
        }
Example #3
0
        /// <summary>
        /// Starts running tests from a single type (if provided) or the whole assembly (if not). This call returns
        /// immediately, and status results are dispatched to the Info>s on this class. Callers can check <see cref="Status"/>
        /// to find out the current status.
        /// </summary>
        /// <param name="typeName">The (optional) type name of the single test class to run</param>
        /// <param name="diagnosticMessages">Set to <c>true</c> to enable diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        /// <param name="methodDisplay">Set to choose the default display name style for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="methodDisplayOptions">Set to choose the default display name style options for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="preEnumerateTheories">Set to <c>true</c> to pre-enumerate individual theory tests; set to <c>false</c> to use
        /// a single test case for the theory. By default, uses the value from the assembly configuration file. (This parameter is ignored
        /// for xUnit.net v1 tests.)</param>
        /// <param name="parallel">Set to <c>true</c> to run test collections in parallel; set to <c>false</c> to run them sequentially.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="maxParallelThreads">Set to 0 to use unlimited threads; set to any other positive integer to limit to an exact number
        /// of threads. By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="internalDiagnosticMessages">Set to <c>true</c> to enable internal diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        public void Start(string typeName                 = null,
                          bool?diagnosticMessages         = null,
                          TestMethodDisplay?methodDisplay = null,
                          TestMethodDisplayOptions?methodDisplayOptions = null,
                          bool?preEnumerateTheories       = null,
                          bool?parallel                   = null,
                          int?maxParallelThreads          = null,
                          bool?internalDiagnosticMessages = null)
        {
            lock (statusLock)
            {
                if (Status != AssemblyRunnerStatus.Idle)
                {
                    throw new InvalidOperationException("Calling Start is not valid when the current status is not idle.");
                }

                cancelled           = false;
                testCasesDiscovered = 0;
                testCasesToRun.Clear();
                discoveryCompleteEvent.Reset();
                executionCompleteEvent.Reset();
            }

            XunitWorkerThread.QueueUserWorkItem(() =>
            {
                var discoveryOptions = GetDiscoveryOptions(diagnosticMessages, methodDisplay, methodDisplayOptions, preEnumerateTheories, internalDiagnosticMessages);
                if (typeName != null)
                {
                    controller.Find(typeName, false, this, discoveryOptions);
                }
                else
                {
                    controller.Find(false, this, discoveryOptions);
                }

                discoveryCompleteEvent.WaitOne();
                if (cancelled)
                {
                    // Synthesize the execution complete message, since we're not going to run at all
                    if (OnExecutionComplete != null)
                    {
                        OnExecutionComplete(ExecutionCompleteInfo.Empty);
                    }
                    return;
                }

                var executionOptions = GetExecutionOptions(diagnosticMessages, parallel, maxParallelThreads, internalDiagnosticMessages);
                controller.RunTests(testCasesToRun, this, executionOptions);
                executionCompleteEvent.WaitOne();
            });
        }
Example #4
0
        public static void SendRequest(IRunnerLogger logger, string url, HttpMethod method, object body)
        {
            if (previousErrors)
            {
                return;
            }

            lock (jsonMediaType)
            {
                using (var finished = new ManualResetEvent(false))
                {
                    XunitWorkerThread.QueueUserWorkItem(async() =>
                    {
                        var bodyString = ToJson(body);

                        try
                        {
                            var bodyBytes = Encoding.UTF8.GetBytes(bodyString);

                            var request     = new HttpRequestMessage(method, url);
                            request.Content = new ByteArrayContent(bodyBytes);
                            request.Content.Headers.ContentType = jsonMediaType;
                            request.Headers.Accept.Add(jsonMediaType);

                            using (var tcs = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
                            {
                                var response = await client.SendAsync(request, tcs.Token);
                                if (!response.IsSuccessStatusCode)
                                {
                                    logger.LogWarning($"When sending '{method} {url}', received status code '{response.StatusCode}'; request body: {bodyString}");
                                    previousErrors = true;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.LogError($"When sending '{method} {url}' with body '{bodyString}', exception was thrown: {ex.Message}");
                            previousErrors = true;
                        }
                        finally
                        {
                            finished.Set();
                        }
                    });

                    finished.WaitOne();
                }
            }
        }
 void HandleTestAssemblyStarting(MessageHandlerArgs <ITestAssemblyStarting> args)
 {
     stopEvent        = new ManualResetEvent(initialState: false);
     lastTestActivity = UtcNow;
     XunitWorkerThread.QueueUserWorkItem(ThreadWorker);
 }