-
Notifications
You must be signed in to change notification settings - Fork 756
Description
Following example will fail to build with :
[TestFixtureSource("FixtureArgs")]
public class TestFixtureAtributeTest {
public TestFixtureAtributeTest(string word, int num) { }
[Test]
public void TestSomething()
{
Assert.That(true, Is.True);
}
static object [] FixtureArgs = {
new object[] { "Question", 1 },
new object[] { "Answer", 42 }
};
}
with following error:
An exception was thrown while loading the test.
System.ArgumentNullException: pathName
Parameter name: Argument pathName must not be null
at NUnit.Framework.Guard.ArgumentNotNull (System.Object value, System.String name) [0x00000] in :0
at NUnit.Framework.Guard.ArgumentNotNullOrEmpty (System.String value, System.String name) [0x00000] in :0
at NUnit.Framework.Internal.Test..ctor (System.String pathName, System.String name) [0x00000] in :0
at NUnit.Framework.Internal.TestSuite..ctor (System.String parentSuiteName, System.String name) [0x00000] in :0
at NUnit.Framework.Internal.ParameterizedFixtureSuite..ctor (ITypeInfo typeInfo) [0x00000] in :0
at NUnit.Framework.Internal.Builders.DefaultSuiteBuilder.BuildMultipleFixtures (ITypeInfo typeInfo, IEnumerable`1 fixtures) [0x00000] in :0
at NUnit.Framework.Internal.Builders.DefaultSuiteBuilder.BuildFrom (ITypeInfo typeInfo) [0x00000] in :0
I managed to fix the issue but discovering a different one where TestFixtureSource with only 1 value will fail to generated the reult. I didn't manage to compile the head cahngeset from master or I'm pasting the patch here (based on 3.5):
diff --git a/src/NUnitFramework/framework/Internal/Tests/Test.cs b/src/NUnitFramework/framework/Internal/Tests/Test.cs
index 044637e..1caccc9 100644
--- a/src/NUnitFramework/framework/Internal/Tests/Test.cs
+++ b/src/NUnitFramework/framework/Internal/Tests/Test.cs
@@ -84,11 +84,12 @@ protected Test( string name )
/// <param name="name">The name of the test</param>
protected Test( string pathName, string name )
{
- Guard.ArgumentNotNullOrEmpty(pathName, "pathName");
-
Initialize(name);
- FullName = pathName + "." + name;
+ if (!string.IsNullOrEmpty(pathName))
+ FullName = pathName + "." + name;
+ else
+ FullName = name;
}
/// <summary>
diff --git a/src/NUnitFramework/testdata/SetUpFixtureData.cs b/src/NUnitFramework/testdata/SetUpFixtureData.cs
index 09c6a42..03cde6f 100644
--- a/src/NUnitFramework/testdata/SetUpFixtureData.cs
+++ b/src/NUnitFramework/testdata/SetUpFixtureData.cs
@@ -600,6 +600,40 @@ public void DoNamespaceTearDown()
}
}
+[TestFixtureSource("MyData")]
+public class NoNamespaceTestFixtureSourceWithTwoValues
+{
+ public NoNamespaceTestFixtureSourceWithTwoValues(int i)
+ {
+
+ }
+
+ [Test]
+ public void Test()
+ {
+ NUnit.TestUtilities.SimpleEventRecorder.RegisterEvent("NoNamespaceTestFixtureSourceWithTwoValues");
+ }
+
+ static object [] MyData = { 1, 2 };
+}
+
+[TestFixtureSource("MyData")]
+public class NoNamespaceTestFixtureSourceWithSingleValue
+{
+ public NoNamespaceTestFixtureSourceWithSingleValue(int i)
+ {
+
+ }
+
+ [Test]
+ public void Test()
+ {
+ NUnit.TestUtilities.SimpleEventRecorder.RegisterEvent("NoNamespaceTestFixtureSourceWithSingleValue");
+ }
+
+ static object [] MyData = { 1 };
+}
+
[TestFixture]
public class SomeFixture
{
diff --git a/src/NUnitFramework/tests/Internal/SetUpFixtureTests.cs b/src/NUnitFramework/tests/Internal/SetUpFixtureTests.cs
index 4cbcf6d..faa5879 100644
--- a/src/NUnitFramework/tests/Internal/SetUpFixtureTests.cs
+++ b/src/NUnitFramework/tests/Internal/SetUpFixtureTests.cs
@@ -251,6 +251,28 @@ public void AssemblySetupFixtureWrapsExecutionOfTest()
"Assembly.OneTimeTearDown");
}
#endregion NoNamespaceSetupFixture
+
+ #region NoNamespaceTestFixtureSource
+ [NUnit.Framework.Test]
+ public void NoNamespaceTestFixtureSourceWithTwoValuesTest()
+ {
+ ITestResult result = runTests(null, new Filters.FullNameFilter("NoNamespaceTestFixtureSourceWithTwoValues"));
+ Assert.AreEqual(2, result.PassCount);
+ Assert.That(result.ResultState.Status, Is.EqualTo(TestStatus.Passed));
+ TestUtilities.SimpleEventRecorder.Verify("Assembly.OneTimeSetUp",
+ "NoNamespaceTestFixtureSourceWithTwoValues");
+ }
+
+ [NUnit.Framework.Test]
+ public void NoNamespaceTestFixtureSourceWithSingleValueTest()
+ {
+ ITestResult result = runTests(null, new Filters.FullNameFilter("NoNamespaceTestFixtureSourceWithSingleValue"));
+ Assert.AreEqual(1, result.PassCount);
+ Assert.That(result.ResultState.Status, Is.EqualTo(TestStatus.Passed));
+ TestUtilities.SimpleEventRecorder.Verify("Assembly.OneTimeSetUp",
+ "NoNamespaceTestFixtureSourceWithSingleValue");
+ }
+ #endregion NoNamespaceTestFixtureSource
}
}
#endif