Esempio n. 1
0
        private static void InvokeTest(object instance, MethodInfo method, TestStatistics stats)
        {
            string testName = $"{method.DeclaringType.Name}.{method.Name}";

            Debug.WriteLine("");
            Debug.WriteLine($"-- Running test {testName}:");

            Exception failure = null;

            try
            {
                method.Invoke(instance, null);
            }
            catch (Exception ex)
            {
                failure = ex;
            }

            if (failure == null)
            {
                Debug.WriteLine("-- Test Passed --");
                stats.AddTestResult(true, testName);
            }
            else
            {
                Debug.WriteLine("!! Test Failed !!");
                Debug.WriteLine($"An exception of type {failure.GetType().FullName} was thrown: {failure.Message}");
                Debug.WriteLine(failure.StackTrace);
                stats.AddTestResult(false, testName);
            }
        }
Esempio n. 2
0
        private static void RunTestClass(TestClassData testData, TestStatistics stats)
        {
            object instance = Activator.CreateInstance(testData.Type);

            foreach (var testMethod in testData.Methods)
            {
                InvokeTest(instance, testMethod, stats);
            }

            testData.DisposeMethod?.Invoke(instance, null);
        }
Esempio n. 3
0
        public void RunAllTests(TestStatistics stats)
        {
            Debug.WriteLine("Beginning test run");

            foreach (var testClass in m_testGrid)
            {
                RunTestClass(testClass, stats);
            }

            Debug.WriteLine("End of test run");
        }
Esempio n. 4
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            TestStatistics stats = new TestStatistics();

            statusTextBlock.Text = "Finding tests...";
            await Task.Run(() =>
            {
                testManager.FindAllTests();
            });

            statusTextBlock.Text = "Running all tests...";

            await Task.Run(() =>
            {
                testManager.RunAllTests(stats);
            });

            stats.PrintSummary();

            statusTextBlock.Text     = "Finished";
            summaryTextBlock.Text    = $"{stats.NumberTestsPassed}/{stats.NumberTestsRun} tests passed ({stats.PercentPassed}%)";
            failuresList.ItemsSource = stats.FailedTests;
        }