Exemplo n.º 1
0
        public void NullCallbackThrows()
        {
            var testAssembly = TestableTestAssembly.Create();
            var testMethod   = testAssembly.Class1.Object.EnumerateTestMethods().First();

            Assert.Throws <ArgumentNullException>(() => testAssembly.Run(new[] { testMethod }, null));
        }
Exemplo n.º 2
0
        public void EmptyTestMethodsThrows()
        {
            var testAssembly = TestableTestAssembly.Create();
            var callback     = new Mock <ITestMethodRunnerCallback>();

            Assert.Throws <ArgumentException>(() => testAssembly.Run(new TestMethod[0], callback.Object));
        }
Exemplo n.º 3
0
        public void TestMethodNotForThisTestAssemblyThrows()
        {
            var testAssembly = TestableTestAssembly.Create();
            var testMethod   = new TestMethod(null, null, null);
            var testClass    = new TestClass(null, new[] { testMethod });
            var callback     = new Mock <ITestMethodRunnerCallback>();

            Assert.Throws <ArgumentException>(() => testAssembly.Run(new[] { testMethod }, callback.Object));
        }
Exemplo n.º 4
0
        public void RunOnlyCallsRunOnClassesWithMethodsToBeRun()
        {
            var        testAssembly  = TestableTestAssembly.Create();
            var        callback      = new Mock <ITestMethodRunnerCallback>();
            TestMethod class1Method1 = testAssembly.Class1.Object.EnumerateTestMethods().First();
            TestMethod class2Method2 = testAssembly.Class2.Object.EnumerateTestMethods().First();

            testAssembly.Class1.Setup(c => c.Run(new[] { class1Method1 }, It.IsAny <ITestMethodRunnerCallback>()))
            .Returns("<class1/>")
            .Verifiable();

            testAssembly.Run(new[] { class1Method1 }, callback.Object);

            testAssembly.Class1.Verify();
            testAssembly.Class2.Verify(c => c.Run(It.IsAny <IEnumerable <TestMethod> >(), callback.Object), Times.Never());
        }
Exemplo n.º 5
0
        public void RunSortsTestsByClassAndCallsRunOnClasses()
        {
            var        testAssembly  = TestableTestAssembly.Create();
            var        callback      = new Mock <ITestMethodRunnerCallback>();
            TestMethod class1Method1 = testAssembly.Class1.Object.EnumerateTestMethods().First();
            TestMethod class2Method2 = testAssembly.Class2.Object.EnumerateTestMethods().First();

            testAssembly.Class1.Setup(c => c.Run(new[] { class1Method1 }, It.IsAny <ITestMethodRunnerCallback>()))
            .Returns("<class1/>")
            .Verifiable();
            testAssembly.Class2.Setup(c => c.Run(new[] { class2Method2 }, It.IsAny <ITestMethodRunnerCallback>()))
            .Returns("<class2/>")
            .Verifiable();

            testAssembly.Run(testAssembly.EnumerateTestMethods(), callback.Object);

            testAssembly.Class1.Verify();
            testAssembly.Class2.Verify();
        }
Exemplo n.º 6
0
        public void RunReturnsAssemblyXml()
        {
            var testAssembly  = TestableTestAssembly.Create();
            var callback      = new Mock <ITestMethodRunnerCallback>();
            var class1Method1 = testAssembly.Class1.Object.EnumerateTestMethods().First();

            class1Method1.RunResults.Add(new TestFailedResult(1.2, "DisplayName", "Output", "ExceptionType", "ExceptionMessage", "ExceptionStackTrace"));
            class1Method1.RunResults.Add(new TestSkippedResult("DisplayName", "Reason"));
            var class2Method2 = testAssembly.Class2.Object.EnumerateTestMethods().First();

            class2Method2.RunResults.Add(new TestPassedResult(2.4, "DisplayName", "Output"));
            testAssembly.Class1.Setup(c => c.Run(new[] { class1Method1 }, It.IsAny <ITestMethodRunnerCallback>()))
            .Returns("<class1/>")
            .Verifiable();
            testAssembly.Class2.Setup(c => c.Run(new[] { class2Method2 }, It.IsAny <ITestMethodRunnerCallback>()))
            .Returns("<class2/>")
            .Verifiable();

            var result = testAssembly.Run(testAssembly.EnumerateTestMethods(), callback.Object);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);
            XmlNode assemblyNode = doc.ChildNodes[0];

            Assert.Equal("AssemblyFilename", assemblyNode.Attributes["name"].Value);
            Assert.Equal("ConfigFilename", assemblyNode.Attributes["configFile"].Value);
            Assert.Equal("3.600", assemblyNode.Attributes["time"].Value);
            Assert.Equal("3", assemblyNode.Attributes["total"].Value);
            Assert.Equal("1", assemblyNode.Attributes["passed"].Value);
            Assert.Equal("1", assemblyNode.Attributes["failed"].Value);
            Assert.Equal("1", assemblyNode.Attributes["skipped"].Value);
            Assert.Equal("<class1 /><class2 />", assemblyNode.InnerXml);
            Assert.NotEmpty(assemblyNode.Attributes["run-date"].Value);
            Assert.NotEmpty(assemblyNode.Attributes["run-time"].Value);
            Assert.NotEmpty(assemblyNode.Attributes["environment"].Value);
            Assert.Contains("xUnit.net", assemblyNode.Attributes["test-framework"].Value);
        }