Merge lp://staging/~adam-rpconnelly/nunit-3.0/bug-487878 into lp://staging/nunit-3.0

Proposed by Adam Connelly
Status: Merged
Merge reported by: Charlie Poole
Merged at revision: not available
Proposed branch: lp://staging/~adam-rpconnelly/nunit-3.0/bug-487878
Merge into: lp://staging/nunit-3.0
Diff against target: 172 lines (+108/-14)
3 files modified
src/framework/Internal/Extensions/NUnitTestFixtureBuilder.cs (+21/-4)
src/test-assembly/TestFixtureData.cs (+33/-0)
src/tests/NUnit/Core/TestFixtureTests.cs (+54/-10)
To merge this branch: bzr merge lp://staging/~adam-rpconnelly/nunit-3.0/bug-487878
Reviewer Review Type Date Requested Status
Charlie Poole Needs Fixing
Review via email: mp+17114@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Adam Connelly (adam-rpconnelly) wrote :

I added an extra test to check that the correct IgnoreReason is specified. Is that sensible or is there no point?

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Looks OK. The extra test is a good idea.

review: Approve
Revision history for this message
Charlie Poole (charlie.poole) wrote :

It looked good, but when I tried to merge, I had 22 non-runnable tests. Problems I see:

1. You didn't pick up the change in BuildFrom, where we only look at inherited attributes when there is no TestFixture attribute on the actual Type.

2. The new code in BuildMultipleFixtures around BuildTypeArgument is not needed and causes spurious messages because the method can be called for non-generic parameterized fixtures.

3. There is actually already an error in BuildMultipleFixtures, which I just noticed. The existing error message about a generic fixture should only display if we are actually building a generic fixture. If we are not, some other message is needed.

review: Needs Fixing
Revision history for this message
Charlie Poole (charlie.poole) wrote :

Adam, have you stopped working on this one? I see that I marked it "needs fixing" and added the last comment back in January. Please let me know if you're stuck or don't plan to go further with it.

Charlie

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/framework/Internal/Extensions/NUnitTestFixtureBuilder.cs'
2--- src/framework/Internal/Extensions/NUnitTestFixtureBuilder.cs 2010-01-10 00:30:25 +0000
3+++ src/framework/Internal/Extensions/NUnitTestFixtureBuilder.cs 2010-01-11 00:00:38 +0000
4@@ -76,7 +76,7 @@
5 {
6 TestFixtureAttribute[] attrs =
7 (TestFixtureAttribute[])type.GetCustomAttributes(typeof(TestFixtureAttribute), false);
8-
9+
10 #if CLR_2_0
11 if (type.IsGenericType)
12 return BuildMultipleFixtures(type, attrs);
13@@ -101,9 +101,26 @@
14 private Test BuildMultipleFixtures(Type type, TestFixtureAttribute[] attrs)
15 {
16 TestSuite suite = new TestSuite(type.Namespace, TypeHelper.GetDisplayName(type));
17-
18- foreach (TestFixtureAttribute attr in attrs)
19- suite.Add(BuildSingleFixture(type, attr));
20+ bool hasTypeArguments = false;
21+
22+ if (attrs.Length > 0)
23+ {
24+ foreach (TestFixtureAttribute attr in attrs)
25+ {
26+ if (!hasTypeArguments && attr.TypeArgs.Length > 0)
27+ {
28+ hasTypeArguments = true;
29+ }
30+
31+ suite.Add(BuildSingleFixture(type, attr));
32+ }
33+ }
34+
35+ if (!hasTypeArguments)
36+ {
37+ suite.RunState = RunState.NotRunnable;
38+ suite.IgnoreReason = "Generic fixture has no type arguments provided";
39+ }
40
41 return suite;
42 }
43
44=== modified file 'src/test-assembly/TestFixtureData.cs'
45--- src/test-assembly/TestFixtureData.cs 2010-01-10 00:30:25 +0000
46+++ src/test-assembly/TestFixtureData.cs 2010-01-11 00:00:38 +0000
47@@ -80,6 +80,39 @@
48 [Test]
49 public static void StaticTest() { }
50 }
51+
52+ [TestFixture(typeof(string))]
53+ public class GenericFixtureWithProperArgsProvided<T>
54+ {
55+ [Test]
56+ public void Test() { }
57+ }
58+
59+ public class GenericFixtureWithNoTestFixtureAttribute<T>
60+ {
61+ [Test]
62+ public void Test() { }
63+ }
64+
65+ [TestFixture]
66+ public class GenericFixtureWithNoArgsProvided<T>
67+ {
68+ [Test]
69+ public void Test() { }
70+ }
71+
72+ public class GenericFixtureDerivedFromAbstractTestFixtureWithNoArgsProvided<T> : AbstractTestFixture
73+ {
74+ [Test]
75+ public void Test() { }
76+ }
77+
78+ [TestFixture(typeof(string))]
79+ public class GenericFixtureDerivedFromAbstractTestFixtureWithArgsProvided<T> : AbstractTestFixture
80+ {
81+ [Test]
82+ public void Test() { }
83+ }
84 #endif
85
86 [TestFixture]
87
88=== modified file 'src/tests/NUnit/Core/TestFixtureTests.cs'
89--- src/tests/NUnit/Core/TestFixtureTests.cs 2010-01-10 00:30:25 +0000
90+++ src/tests/NUnit/Core/TestFixtureTests.cs 2010-01-11 00:00:38 +0000
91@@ -70,16 +70,6 @@
92 Assert.AreEqual("NUnit.TestData.TestFixtureData.FixtureWithoutTestFixtureAttribute", fixture.FullName);
93 }
94
95-#if CLR_2_0
96- [Test]
97- public void ConstructFromStaticTypeWithoutTestFixtureAttribute()
98- {
99- TestSuite fixture = TestBuilder.MakeFixture(typeof(StaticFixtureWithoutTestFixtureAttribute));
100- Assert.AreEqual("StaticFixtureWithoutTestFixtureAttribute", fixture.Name);
101- Assert.AreEqual("NUnit.TestData.TestFixtureData.StaticFixtureWithoutTestFixtureAttribute", fixture.FullName);
102- }
103-#endif
104-
105 [Test]
106 public void CannotRunConstructorWithArgsNotSupplied()
107 {
108@@ -138,10 +128,64 @@
109
110 #if CLR_2_0
111 [Test]
112+ public void ConstructFromStaticTypeWithoutTestFixtureAttribute()
113+ {
114+ TestSuite fixture = TestBuilder.MakeFixture(typeof(StaticFixtureWithoutTestFixtureAttribute));
115+ Assert.AreEqual("StaticFixtureWithoutTestFixtureAttribute", fixture.Name);
116+ Assert.AreEqual("NUnit.TestData.TestFixtureData.StaticFixtureWithoutTestFixtureAttribute", fixture.FullName);
117+ }
118+
119+ [Test]
120 public void CanRunStaticFixture()
121 {
122 TestAssert.IsRunnable(typeof(StaticFixtureWithoutTestFixtureAttribute));
123 }
124+
125+ [Test]
126+ public void CanRunGenericFixtureWithProperArgsProvided()
127+ {
128+ TestAssert.IsRunnable(
129+ Type.GetType("NUnit.TestData.TestFixtureData.GenericFixtureWithProperArgsProvided`1,test-assembly"));
130+ }
131+
132+ [Test]
133+ public void CannotRunGenericFixtureWithNoTestFixtureAttribute()
134+ {
135+ TestAssert.IsNotRunnable(
136+ Type.GetType("NUnit.TestData.TestFixtureData.GenericFixtureWithNoTestFixtureAttribute`1,test-assembly"));
137+ }
138+
139+ [Test]
140+ public void CannotRunGenericFixtureWithNoArgsProvided()
141+ {
142+ TestAssert.IsNotRunnable(
143+ Type.GetType("NUnit.TestData.TestFixtureData.GenericFixtureWithNoArgsProvided`1,test-assembly"));
144+ }
145+
146+ [Test]
147+ public void CorrectIgnoreReasonIsProvidedForGenericFixtureWithNoArgsProvided()
148+ {
149+ TestSuite suite = TestBuilder.MakeFixture(
150+ Type.GetType("NUnit.TestData.TestFixtureData.GenericFixtureWithNoArgsProvided`1,test-assembly"));
151+
152+ Assert.That(suite.IgnoreReason,
153+ Is.EqualTo("Generic fixture has no type arguments provided"),
154+ "Should have provided an ignore reason for generic tests without type arguments provided");
155+ }
156+
157+ [Test]
158+ public void CannotRunGenericFixtureDerivedFromAbstractTestFixtureWithNoArgsProvided()
159+ {
160+ TestAssert.IsNotRunnable(
161+ Type.GetType("NUnit.TestData.TestFixtureData.GenericFixtureDerivedFromAbstractTestFixtureWithNoArgsProvided`1,test-assembly"));
162+ }
163+
164+ [Test]
165+ public void CanRunGenericFixtureDerivedFromAbstractTestFixtureWithArgsProvided()
166+ {
167+ TestAssert.IsRunnable(
168+ Type.GetType("NUnit.TestData.TestFixtureData.GenericFixtureDerivedFromAbstractTestFixtureWithArgsProvided`1,test-assembly"));
169+ }
170 #endif
171
172 [Test]

Subscribers

People subscribed via source and target branches