The Test abstract class represents a test within the framework.
Inheritance: ITest, IComparable
        /// <inheritdoc />
        protected override NUnit.Framework.Internal.Test LoadTest(ITestAssemblyRunner runner, Assembly assembly,
                                                                  IDictionary <string, object> settings)
        {
            // Return null test
            if (IsLoadedTestNull)
            {
                IsLoadedTestNull = false;
                return(null);
            }

            // Return test with RunState as NotRunnable
            if (IsLoadedTestInvalid)
            {
                IsLoadedTestInvalid = false;
                TestSuite suite = new TestSuite(assembly.FullName);
                suite.RunState = RunState.NotRunnable;
                return(suite);
            }

            // Return base functionality
            if (TestToLoad == null)
            {
                return(base.LoadTest(runner, assembly, settings));
            }

            // Return custom test
            NUnit.Framework.Internal.Test test = TestToLoad;
            TestToLoad = null;
            return(test);
        }
Ejemplo n.º 2
0
 public TestCaseElement(NUnit.Framework.Internal.Test test) : base(test)
 {
     if (test.RunState == RunState.Runnable)
     {
         Indicator = "...";                 // hint there's more
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestMethod"/> class.
 /// </summary>
 /// <param name="method">The method to be used as a test.</param>
 /// <param name="parentSuite">The suite or fixture to which the new test will be added</param>
 public TestMethod(IMethodInfo method, Test parentSuite) : base(method ) 
 {
     // Needed to give proper fullname to test in a parameterized fixture.
     // Without this, the arguments to the fixture are not included.
     if (parentSuite != null)
         FullName = parentSuite.FullName + "." + Name;
 }
Ejemplo n.º 4
0
 NUnitTest SetupTestTarget()
 {
     if (current_test == null)
     {
         current_test = AndroidRunner.GetSetupTestTarget(Intent);
     }
     return(current_test);
 }
Ejemplo n.º 5
0
        public TestResult Run(NUnit.Framework.Internal.Test test)
        {
            TestExecutionContext current = TestExecutionContext.CurrentContext;

            current.WorkDirectory = Environment.CurrentDirectory;
            current.Listener      = this;
            current.TestObject    = test is TestSuite ? null : Reflect.Construct((test as TestMethod).Method.ReflectedType, null);
            WorkItem wi = WorkItem.CreateWorkItem(test, current, this);

            wi.Execute();
            return(wi.Result);
        }
        public TestMethod BuildFrom(IMethodInfo method, NUnit.Framework.Internal.Test suite)
        {
            var defaultParameters = method.GetParameters().Select(
                parameter => TypeUtils.defaultOf(parameter.ParameterType)).ToArray();
            var parameters = new TestCaseParameters(defaultParameters);

            if (method.ReturnType.Type != typeof(void))
            {
                parameters.ExpectedResult = null;
            }
            return(_builder.BuildTestMethod(method, suite, parameters));
        }
Ejemplo n.º 7
0
 IEnumerable <NUnitTest> GetChildTests(NUnitTest test)
 {
     if (test is TestSuite)
     {
         foreach (NUnitTest child in ((TestSuite)test).Tests)
         {
             yield return(child);
         }
     }
     else
     {
         yield return(test);
     }
 }
        public void ApplyToTest(NUnit.Framework.Internal.Test test)
        {
            if (test.RunState == RunState.NotRunnable)
            {
                return;
            }

            if (IsSupported(out var message))
            {
                return;
            }

            test.RunState = RunState.Ignored;
            test.Properties.Set(PropertyNames.SkipReason, message !);
        }
Ejemplo n.º 9
0
        public Task <TestResult> Run(NUnit.Framework.Internal.Test test)
        {
            return(Task.Run(() =>
            {
                TestExecutionContext current = TestExecutionContext.CurrentContext;
                current.WorkDirectory = Environment.CurrentDirectory;
                //current.Listener = this; // Internal on Android
                current.GetType().GetField("listener", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(current, this);
                current.TestObject = test is TestSuite ? null : Reflect.Construct((test as TestMethod).Method.ReflectedType, null);
                WorkItem wi = test.CreateWorkItem(TestFilter.Empty);

                wi.Execute(current);
                return wi.Result;
            }));
        }
Ejemplo n.º 10
0
        internal TestResult Run(NUnitTest test, Context context)
        {
            if (!OpenWriter("Run Everything", context))
            {
                return(null);
            }

            try {
                return(Run(test));
            } finally {
                int testCount = passed + failed + skipped + inconclusive;
                Runner.Writer.WriteLine("Tests run: {0}, Passed: {1}, Failed: {2}, Skipped: {3}, Inconclusive: {4}",
                                        testCount, passed, failed, skipped, inconclusive);
                CloseWriter();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestMethod"/> class.
        /// </summary>
        /// <param name="method">The method to be used as a test.</param>
        /// <param name="parentSuite">The suite or fixture to which the new test will be added</param>
        public TestMethod(MethodInfo method, Test parentSuite) 
            : base( method ) 
        {
            // Disambiguate call to base class methods
            // TODO: This should not be here - it's a presentation issue
            //if( method.DeclaringType != method.ReflectedType)
            //    this.Name = method.DeclaringType.Name + "." + method.Name;

            // Needed to give proper fullname to test in a parameterized fixture.
            // Without this, the arguments to the fixture are not included.
            string prefix = method.ReflectedType.FullName;
            if (parentSuite != null)
            {
                prefix = parentSuite.FullName;
                this.FullName = prefix + "." + this.Name;
            }

            //this.method = method;
        }
Ejemplo n.º 12
0
        public TestResult Run(NUnit.Framework.Internal.Test test)
        {
            TestExecutionContext current = TestExecutionContext.CurrentContext;

            current.WorkDirectory = System.Environment.CurrentDirectory;
            current.Listener      = this;
            current.TestObject    = test is TestSuite ? null : Reflect.Construct((test as TestMethod).Method.ReflectedType, null);
            WorkItem wi = test.CreateWorkItem(Filter ?? TestFilter.Empty);

            if (test is TestMethod)
            {
                (test.Parent as TestSuite).GetOneTimeSetUpCommand().Execute(current);
            }
            wi.Execute(current);
            if (test is TestMethod)
            {
                (test.Parent as TestSuite).GetOneTimeTearDownCommand().Execute(current);
            }
            return(wi.Result);
        }
Ejemplo n.º 13
0
        private IList <NUnit.Framework.Internal.Test> GetFixtures(Assembly assembly)
        {
            var fixtures = new List <NUnit.Framework.Internal.Test>();

            log.Debug("Examining assembly for test fixtures");

            var testTypes = GetCandidateFixtureTypes(assembly);

            log.Debug("Found {0} classes to examine", testTypes.Count);
#if LOAD_TIMING
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
#endif
            int testcases = 0;
            foreach (Type testType in testTypes)
            {
                var typeInfo = new TypeWrapper(testType);

                // Any exceptions from this call are fatal problems in NUnit itself,
                // since this is always DefaultSuiteBuilder and the current implementation
                // of DefaultSuiteBuilder.CanBuildFrom cannot invoke any user code.
                if (_defaultSuiteBuilder.CanBuildFrom(typeInfo))
                {
                    // We pass the filter for use in selecting methods of the type.
                    // Any exceptions from this call are fatal problems in NUnit itself,
                    // since this is always DefaultSuiteBuilder and the current implementation
                    // of DefaultSuiteBuilder.BuildFrom handles all exceptions from user code.
                    NUnit.Framework.Internal.Test fixture = _defaultSuiteBuilder.BuildFrom(typeInfo, _filter);
                    fixtures.Add(fixture);
                    testcases += fixture.TestCaseCount;
                }
            }

#if LOAD_TIMING
            log.Debug("Found {0} fixtures with {1} test cases in {2} seconds", fixtures.Count, testcases, timer.Elapsed);
#else
            log.Debug("Found {0} fixtures with {1} test cases", fixtures.Count, testcases);
#endif

            return(fixtures);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Construct one or more TestMethods from a given MethodInfo,
        /// using available parameter data.
        /// </summary>
        /// <param name="method">The MethodInfo for which tests are to be constructed.</param>
        /// <param name="suite">The suite to which the tests will be added.</param>
        /// <returns>One or more TestMethods</returns>
        public IEnumerable <TestMethod> BuildFrom(MethodInfo method, Internal.Test suite)
        {
            ParameterInfo[] parameters = method.GetParameters();

            List <TestMethod> tests = new List <TestMethod>();

            if (parameters.Length > 0)
            {
                IEnumerable[] sources = new IEnumerable[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                {
                    sources[i] = _dataProvider.GetDataFor(parameters[i]);
                }

                foreach (var parms in new CombinatorialStrategy().GetTestCases(sources))
                {
                    tests.Add(_builder.BuildTestMethod(method, suite, (ParameterSet)parms));
                }
            }

            return(tests);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Causes a test to be skipped if this LibpcapVersion is not satisfied.
 /// </summary>
 /// <param name="test">The test to modify</param>
 public void ApplyToTest(NUnit.Framework.Internal.Test test)
 {
     if (test.RunState != RunState.NotRunnable &&
         test.RunState != RunState.Ignored)
     {
         try
         {
             if (
                 (Include != null && !IsVersionSupported(Include)) ||
                 (Exclude != null && IsVersionSupported(Exclude))
                 )
             {
                 var reason = string.Format("Not supported on Libpcap v{0}", Pcap.LibpcapVersion);
                 test.RunState = RunState.Skipped;
                 test.Properties.Add(PropertyNames.SkipReason, reason);
             }
         }
         catch (Exception ex)
         {
             test.RunState = RunState.NotRunnable;
             test.Properties.Add(PropertyNames.SkipReason, ex.Message);
         }
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Construct a TestAdapter for a Test
 /// </summary>
 /// <param name="test">The Test to be adapted</param>
 public TestAdapter(Test test)
 {
     this.test = test;
 }
Ejemplo n.º 17
0
        internal void Run(NUnitTest test, Context context)
        {
            if (!OpenWriter ("Run Everything", context))
                return;

            try {
                Run (test);
            } finally {
                int testCount = passed + failed + skipped + inconclusive;
                Runner.Writer.WriteLine ("Tests run: {0}, Passed: {1}, Failed: {2}, Skipped: {3}, Inconclusive: {4}",
                                         testCount, passed, failed, skipped, inconclusive);
                CloseWriter ();
            }
        }
Ejemplo n.º 18
0
        private void CheckXmlForTest(Test test, TNode topNode, bool recursive)
        {
            Assert.NotNull(topNode);

            //if (test is TestSuite)
            //{
            //    Assert.That(xmlNode.Name, Is.EqualTo("test-suite"));
            //    Assert.That(xmlNode.Attributes["type"].Value, Is.EqualTo(test.XmlElementName));
            //}
            //else
            //{
            //    Assert.That(xmlNode.Name, Is.EqualTo("test-case"));
            //}

            Assert.That(topNode.Name, Is.EqualTo(test.XmlElementName));
            Assert.That(topNode.Attributes["id"], Is.EqualTo(test.Id.ToString()));
            Assert.That(topNode.Attributes["name"], Is.EqualTo(test.Name));
            Assert.That(topNode.Attributes["fullname"], Is.EqualTo(test.FullName));
            if (test.Type != null)
            {
                Assert.NotNull(test.ClassName);
                Assert.That(topNode.Attributes["classname"], Is.EqualTo(test.ClassName));
            }
            if (test is TestMethod)
            {
                Assert.NotNull(test.MethodName);
                Assert.That(topNode.Attributes["methodname"], Is.EqualTo(test.MethodName));
            }
            Assert.That(topNode.Attributes["runstate"], Is.EqualTo(test.RunState.ToString()));

            if (test.Properties.Keys.Count > 0)
            {
                var expectedProps = new List <string>();
                foreach (string key in test.Properties.Keys)
                {
                    foreach (object value in test.Properties[key])
                    {
                        expectedProps.Add(key + "=" + value.ToString());
                    }
                }

                TNode propsNode = topNode.SelectSingleNode("properties");
                Assert.NotNull(propsNode);

                var actualProps = new List <string>();
                foreach (TNode node in propsNode.ChildNodes)
                {
                    string name  = node.Attributes["name"];
                    string value = node.Attributes["value"];
                    actualProps.Add(name + "=" + value.ToString());
                }

                Assert.That(actualProps, Is.EquivalentTo(expectedProps));
            }

            if (recursive)
            {
                TestSuite suite = test as TestSuite;
                if (suite != null)
                {
                    foreach (Test child in suite.Tests)
                    {
                        string xpathQuery = string.Format("{0}[@id={1}]", child.XmlElementName, child.Id);
                        TNode  childNode  = topNode.SelectSingleNode(xpathQuery);
                        Assert.NotNull(childNode, "Expected node for test with ID={0}, Name={1}", child.Id, child.Name);

                        CheckXmlForTest(child, childNode, recursive);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private void CheckXmlForTest(Test test, bool recursive)
        {
            TNode topNode = test.ToXml(true);

            CheckXmlForTest(test, topNode, recursive);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Adds the XML representation of the result as a child of the
        /// supplied parent node..
        /// </summary>
        /// <param name="parentNode">The parent node.</param>
        /// <param name="recursive">If true, descendant results are included</param>
        /// <returns></returns>
        public virtual TNode AddToXml(TNode parentNode, bool recursive)
        {
            // A result node looks like a test node with extra info added
            TNode thisNode = Test.AddToXml(parentNode, false);

            thisNode.AddAttribute("result", ResultState.Status.ToString());
            if (ResultState.Label != string.Empty) // && ResultState.Label != ResultState.Status.ToString())
            {
                thisNode.AddAttribute("label", ResultState.Label);
            }
            if (ResultState.Site != FailureSite.Test)
            {
                thisNode.AddAttribute("site", ResultState.Site.ToString());
            }

            thisNode.AddAttribute("start-time", StartTime.ToString("u"));
            thisNode.AddAttribute("end-time", EndTime.ToString("u"));
            thisNode.AddAttribute("duration", Duration.ToString("0.000000", NumberFormatInfo.InvariantInfo));

            if (Test is TestSuite)
            {
                thisNode.AddAttribute("total", (PassCount + FailCount + SkipCount + InconclusiveCount).ToString());
                thisNode.AddAttribute("passed", PassCount.ToString());
                thisNode.AddAttribute("failed", FailCount.ToString());
                thisNode.AddAttribute("warnings", WarningCount.ToString());
                thisNode.AddAttribute("inconclusive", InconclusiveCount.ToString());
                thisNode.AddAttribute("skipped", SkipCount.ToString());
            }

            thisNode.AddAttribute("asserts", AssertCount.ToString());

            switch (ResultState.Status)
            {
            case TestStatus.Failed:
                AddFailureElement(thisNode);
                break;

            case TestStatus.Skipped:
            case TestStatus.Passed:
            case TestStatus.Inconclusive:
            case TestStatus.Warning:
                if (Message != null)
                {
                    AddReasonElement(thisNode);
                }
                break;
            }

            if (Output.Length > 0)
            {
                AddOutputElement(thisNode);
            }

            if (AssertionResults.Count > 0)
            {
                AddAssertionsElement(thisNode);
            }


            if (recursive && HasChildren)
            {
                foreach (TestResult child in Children)
                {
                    child.AddToXml(thisNode, recursive);
                }
            }

            return(thisNode);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Adds a test to the suite.
 /// </summary>
 /// <param name="test">The test.</param>
 public void Add(Test test)
 {
     test.Parent = this;
     tests.Add(test);
 }