Exemplo n.º 1
0
        private void InitTest(TestBase _test)
        {
            OnTestStart?.Invoke(_test);

            try
            {
                _test.Initialize();
                _test.Iterations = 0;
            }
            catch (Exception ex)
            {
                _test.Exception = ex;
                OnException?.Invoke(_test, ex);
                throw ex;
            }
        }
 public void Execute()
 {
     m_test = (SA_BaseTest)Activator.CreateInstance(m_testConfig.TestReference.Type);
     OnTestStart.Invoke();
     OnTestStart      = delegate { };
     m_test.OnResult += TestResultHandler;
     if (!m_test.RequireUserInteraction)
     {
         // m_timeoutCoroutine = SA_Coroutine.WaitForSeconds(TIMEOUT, OnTimeOut);
         SA_Coroutine.WaitForSeconds(TIMEOUT, OnTimeOut);
     }
     try {
         m_test.Test();
     }
     catch (Exception e) {
         ClearListener();
         FireResult(SA_TestResult.WithError("Failed with Exception " + e.GetBaseException().Message));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Execute all tests and return IEnumerable with test output
        /// </summary>
        /// <param name="assembly">assembly with test methods</param>
        /// <param name="tasksCount">amount of parallel tests (use processorCount when -1)</param>
        /// <returns>IEnumerable with test output</returns>
        public static async Task <IEnumerable <TestResult> > RunTestsAsync(Assembly assembly = null,
                                                                           int tasksCount    = -1)
        {
            var testResults = new List <Task <TestResult> >();

            using var maxTasks = new SemaphoreSlim(tasksCount == -1 ? Environment.ProcessorCount : tasksCount);
            foreach (var test in LoadTests(assembly))
            {
                await maxTasks.WaitAsync();

                OnTestStart?.Invoke(test);

                var task = test.Execute();
                testResults.Add(task);
                task.ContinueWith(ta =>
                {
                    OnTestComplete?.Invoke(ta.Result);
                    return(maxTasks.Release());
                });
            }

            return(await Task.WhenAll(testResults));
        }