Example #1
0
        private static IMessageSinkMessage GetMessageFromTestResult(ITest test, ITestResult testResult)
        {
            var failed = testResult as TestFailed;

            if (failed != null)
            {
                return(new Xunit.Sdk.TestFailed(test, failed.ExecutionTime, failed.Output, failed.ExceptionTypes, failed.ExceptionMessages, failed.ExceptionStackTraces, new [] { -1 }));
            }
            var skipped = testResult as TestSkipped;

            if (skipped != null)
            {
                return(new Xunit.Sdk.TestSkipped(test, skipped.SkipReason));
            }
            var passed = testResult as TestPassed;

            if (passed != null)
            {
                return(new Xunit.Sdk.TestPassed(test, passed.ExecutionTime, passed.Output));
            }
            var resultTypeName = testResult?.GetType().FullName ?? "<unknown>";

            throw new TestExecutionException("Cannot get message for the following implementation of `ITestExecutionResult`: " + resultTypeName);
        }
        public override void Run(IList <TestAssemblyInfo> testAssemblies)
        {
            if (testAssemblies == null)
            {
                throw new ArgumentNullException(nameof(testAssemblies));
            }

            if (AssemblyFilters == null || AssemblyFilters.Count == 0)
            {
                runAssemblyByDefault = true;
            }
            else
            {
                runAssemblyByDefault = AssemblyFilters.Values.Any(v => !v);
            }

            var builder   = new NUnitLiteTestAssemblyBuilder();
            var runner    = new NUnitLiteTestAssemblyRunner(builder, new FinallyDelegate());
            var testSuite = new TestSuite(NSBundle.MainBundle.BundleIdentifier);

            results = new TestSuiteResult(testSuite);

            TotalTests = 0;
            foreach (TestAssemblyInfo assemblyInfo in testAssemblies)
            {
                if (assemblyInfo == null || assemblyInfo.Assembly == null || !ShouldRunAssembly(assemblyInfo))
                {
                    continue;
                }

                if (!runner.Load(assemblyInfo.Assembly, builderSettings))
                {
                    OnWarning($"Failed to load tests from assembly '{assemblyInfo.Assembly}");
                    continue;
                }
                if (runner.LoadedTest is NUnitTest tests)
                {
                    TotalTests += tests.TestCaseCount;
                    testSuite.Add(tests);
                }

                // Messy API. .Run returns ITestResult which is, in reality, an instance of TestResult since that's
                // what WorkItem returns and we need an instance of TestResult to add it to TestSuiteResult. So, cast
                // the return to TestResult and hope for the best.
                ITestResult result = null;
                try {
                    OnAssemblyStart(assemblyInfo.Assembly);
                    result = runner.Run(this, Filter);
                } finally {
                    OnAssemblyFinish(assemblyInfo.Assembly);
                }

                if (result == null)
                {
                    continue;
                }

                var testResult = result as TestResult;
                if (testResult == null)
                {
                    throw new InvalidOperationException($"Unexpected test result type '{result.GetType ()}'");
                }
                results.AddResult(testResult);
            }

            // NUnitLite doesn't report filtered tests at all, but we can calculate here
            FilteredTests = TotalTests - ExecutedTests;
            LogFailureSummary();
        }
Example #3
0
        public override void Run(IList <TestAssemblyInfo> testAssemblies)
        {
            if (testAssemblies == null)
            {
                throw new ArgumentNullException(nameof(testAssemblies));
            }

            var builder   = new NUnitLiteTestAssemblyBuilder();
            var runner    = new NUnitLiteTestAssemblyRunner(builder);
            var testSuite = new TestSuite(global::Android.App.Application.Context.PackageName);

            results = new TestSuiteResult(testSuite);

            foreach (TestAssemblyInfo assemblyInfo in testAssemblies)
            {
                if (assemblyInfo == null || assemblyInfo.Assembly == null)
                {
                    continue;
                }

                if (!runner.Load(assemblyInfo.Assembly, builderSettings))
                {
                    OnWarning($"Failed to load tests from assembly '{assemblyInfo.Assembly}");
                    continue;
                }
                if (runner.LoadedTest is NUnitTest tests)
                {
                    testSuite.Add(tests);
                }

                // Messy API. .Run returns ITestResult which is, in reality, an instance of TestResult since that's
                // what WorkItem returns and we need an instance of TestResult to add it to TestSuiteResult. So, cast
                // the return to TestResult and hope for the best.
                ITestResult result = null;
                try {
                    OnAssemblyStart(assemblyInfo.Assembly);
                    result = runner.Run(this, Filter);
                } finally {
                    OnAssemblyFinish(assemblyInfo.Assembly);
                }

                if (result == null)
                {
                    continue;
                }

                var testResult = result as TestResult;
                if (testResult == null)
                {
                    throw new InvalidOperationException($"Unexpected test result type '{result.GetType ()}'");
                }
                results.AddResult(testResult);
            }

            LogFailureSummary();
        }