Esempio n. 1
0
        public ResultsDto Execute(string fixtureName, string testName)
        {
            var listener = new TestRunEventListener();
            listener.RunStarted();

            // If no fixture name is specified execute all the tests.
            if (String.IsNullOrEmpty(fixtureName))
            {
                foreach (var fixture in _fixtures)
                    ExecuteFixture(fixture, listener);
            }
            // If there is a fixture specified but no test, run all the tests in that fixture.
            else if (String.IsNullOrEmpty(testName))
            {
                var fixture = FindFixture(fixtureName);
                ExecuteFixture(fixture, listener);
            }
            // If both a fixture and a test is specified then execute only the specified test.
            else
            {
                var fixture = FindFixture(fixtureName);

                var fixtureInstance = _settings.TestFixtureFactory.InstantiateFixture(fixture.Type);

                var method = fixture.Tests.FirstOrDefault(m => string.Compare(m.Name, testName, true) == 0);
                if (method == null)
                    throw new InvalidOperationException("Invalid integration test " + testName);

                InvokeTest(fixtureInstance, fixtureName, method, listener);
            }

            listener.RunFinished();
            return listener.Results;
        }
Esempio n. 2
0
 private void ExecuteFixture(NUnitTestFixture fixture, TestRunEventListener listener)
 {
     var fixtureInstance = _settings.TestFixtureFactory.InstantiateFixture(fixture.Type);
     foreach (var method in fixture.Tests)
         InvokeTest(fixtureInstance, fixture.Name, method, listener);
 }
Esempio n. 3
0
        private void InvokeTest(object fixtureInstance, string fixtureName, MethodInfo method, TestRunEventListener listener)
        {
            listener.TestStarted(fixtureName, method.Name);
            try
            {
                method.Invoke(fixtureInstance, null);
            }
            catch (TargetInvocationException e)
            {
                Exception innerException = e.InnerException;

                if (innerException is AssertionException)
                {
                    listener.TestFinished(true, false, innerException.Message, null);
                }
                    //
                else if (innerException is SuccessException)
                {
                    listener.TestFinished(false, false, innerException.Message, null);
                }
                else
                {
                    listener.TestFinished(true, true, innerException.Message, innerException.ToString());
                }

                return;
            }

            listener.TestFinished(false, false, null, null);
        }
Esempio n. 4
0
        private void InvokeTest(object fixtureInstance, string fixtureName, MethodInfo method, TestRunEventListener listener)
        {
            listener.TestStarted(fixtureName, method.Name);
            try
            {
                method.Invoke(fixtureInstance, null);
            }
            catch (TargetInvocationException e)
            {
                var assertException = e.InnerException as AssertionException;
                if (assertException != null)
                    listener.TestFinished(true, false, assertException.Message, null);
                else
                {
                    var executorException = e.InnerException as ExecutorScopeException;
                    var realException = (executorException != null) ? executorException.InnerException : e.InnerException;
                    listener.TestFinished(true, true, realException.Message, realException.ToString());
                }

                return;
            }

            listener.TestFinished(false, false, null, null);
        }