~adam-rpconnelly/nunit-3.0/bug-483845

« back to all changes in this revision

Viewing changes to src/tests/Api/TestResultTests.cs

  • Committer: Charlie Poole
  • Date: 2010-01-08 17:21:03 UTC
  • Revision ID: charlie@nunit.com-20100108172103-o065jps8sbft4hhq
Further simplification of API and internals: Removing TestInfo and NUnitFramework classes, eliminating all references to the framework from the test runner and using xml to communicate results back to the runner.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ***********************************************************************
 
2
// Copyright (c) 2010 Charlie Poole
 
3
//
 
4
// Permission is hereby granted, free of charge, to any person obtaining
 
5
// a copy of this software and associated documentation files (the
 
6
// "Software"), to deal in the Software without restriction, including
 
7
// without limitation the rights to use, copy, modify, merge, publish,
 
8
// distribute, sublicense, and/or sell copies of the Software, and to
 
9
// permit persons to whom the Software is furnished to do so, subject to
 
10
// the following conditions:
 
11
// 
 
12
// The above copyright notice and this permission notice shall be
 
13
// included in all copies or substantial portions of the Software.
 
14
// 
 
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
16
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
17
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
18
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
19
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
20
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
21
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
// ***********************************************************************
 
23
 
 
24
using System;
 
25
using System.Xml;
 
26
using NUnit.Framework.Internal;
 
27
using NUnit.TestUtilities;
 
28
 
 
29
namespace NUnit.Framework.Api
 
30
{
 
31
        /// <summary>
 
32
        /// Summary description for TestResultTests.
 
33
        /// </summary>
 
34
        [TestFixture]
 
35
        public class TestResultTests
 
36
        {
 
37
                private TestResult testResult;
 
38
        XmlDocument doc = new XmlDocument();
 
39
 
 
40
                [SetUp]
 
41
                public void SetUp()
 
42
                {
 
43
                        testResult = new TestResult( new TestMethod(Reflect.GetNamedMethod( this.GetType(), "DummyMethod" ) ) );
 
44
                }
 
45
 
 
46
                public void DummyMethod() { }
 
47
 
 
48
        private void PerformCommonXmlTests(XmlNode element)
 
49
        {
 
50
            Assert.True(element is XmlElement);
 
51
            Assert.AreEqual("test", element.Name);
 
52
            Assert.AreEqual("DummyMethod", element.Attributes["name"].Value);
 
53
            Assert.AreEqual("NUnit.Framework.Api.TestResultTests.DummyMethod", element.Attributes["fullname"].Value);
 
54
            Assert.AreEqual("0.000", element.Attributes["time"].Value);
 
55
        }
 
56
                
 
57
                [Test]
 
58
                public void DefaultResult()
 
59
                {
 
60
                        Assert.AreEqual( ResultState.Inconclusive, testResult.ResultState );
 
61
                }
 
62
 
 
63
        [Test]
 
64
        public void DefaultResultToXml()
 
65
        {
 
66
            doc.LoadXml(testResult.ToXml());
 
67
            XmlNode element = doc.FirstChild;
 
68
            PerformCommonXmlTests(element);
 
69
            Assert.AreEqual("Inconclusive", element.Attributes["result"].Value);
 
70
            Assert.Null(element.SelectSingleNode("message"));
 
71
            Assert.Null(element.SelectSingleNode("stacktrace"));
 
72
        }
 
73
 
 
74
        [Test]
 
75
                public void SuccessResult()
 
76
                {
 
77
                        testResult.Success();
 
78
                        Assert.IsTrue(testResult.IsSuccess, "result should be success");
 
79
        }
 
80
 
 
81
        [Test]
 
82
        public void SuccessResultToXml()
 
83
        {
 
84
            testResult.Success();
 
85
            doc.LoadXml(testResult.ToXml());
 
86
            XmlNode element = doc.FirstChild;
 
87
            PerformCommonXmlTests(element);
 
88
            Assert.AreEqual("Success", element.Attributes["result"].Value);
 
89
            Assert.Null(element.SelectSingleNode("message"));
 
90
            Assert.Null(element.SelectSingleNode("stacktrace"));
 
91
        }
 
92
 
 
93
        [Test]
 
94
                public void IgnoredResult()
 
95
                {
 
96
                        testResult.Ignore( "because" );
 
97
                        Assert.AreEqual( false, testResult.Executed );
 
98
                        Assert.AreEqual( "because", testResult.Message );
 
99
        }
 
100
 
 
101
        [Test]
 
102
        public void IgnoredResultToXml()
 
103
        {
 
104
            testResult.Ignore("because");
 
105
            doc.LoadXml(testResult.ToXml());
 
106
            XmlNode element = doc.FirstChild;
 
107
            PerformCommonXmlTests(element);
 
108
            Assert.AreEqual("Ignored", element.Attributes["result"].Value);
 
109
            Assert.NotNull(element.SelectSingleNode("message"));
 
110
            Assert.AreEqual("because", element.SelectSingleNode("message").InnerText);
 
111
            Assert.Null(element.SelectSingleNode("stacktrace"));
 
112
        }
 
113
 
 
114
        [Test]
 
115
                public void FailedResult()
 
116
                {
 
117
                        testResult.Failure("message", "stack trace");
 
118
                        Assert.IsTrue(testResult.IsFailure);
 
119
                        Assert.IsFalse(testResult.IsSuccess);
 
120
                        Assert.AreEqual("message",testResult.Message);
 
121
                        Assert.AreEqual("stack trace",testResult.StackTrace);
 
122
                }
 
123
 
 
124
        [Test]
 
125
        public void FailedResultToXml()
 
126
        {
 
127
            testResult.Failure("message", "stack trace");
 
128
            doc.LoadXml(testResult.ToXml());
 
129
            XmlNode element = doc.FirstChild;
 
130
            PerformCommonXmlTests(element);
 
131
 
 
132
            Assert.AreEqual("Failure", element.Attributes["result"].Value);
 
133
            XmlNode failureNode = element.SelectSingleNode("failure");
 
134
            Assert.NotNull(failureNode, "No failure element found");
 
135
 
 
136
            XmlNode messageNode = failureNode.SelectSingleNode("message");
 
137
            Assert.NotNull(messageNode, "No message element found");
 
138
            Assert.AreEqual("message", messageNode.InnerText);
 
139
 
 
140
            XmlNode stacktraceNode = failureNode.SelectSingleNode("stacktrace");
 
141
            Assert.NotNull(stacktraceNode, "No stacktrace element found");
 
142
            Assert.AreEqual("stack trace", stacktraceNode.InnerText);
 
143
        }
 
144
    }
 
145
}