I have made a parameterized test fixture in play mode which exactly the same with the demo code in nunit official documentation:TestFixture | NUnit Docs , as the attached file “ParameterizedTestFixture.cs”.
but he Unit Test Runner window shows error for this testfixture:
ParameterizedTestFixture (0.000s)
—
An exception was thrown while loading the test.
System.ArgumentNullException: pathName
Parameter name: Argument pathName must not be null
If i add a namespace for the testfixture, sth like:
namespace Test
{
[TestFixture]
[TestFixture("hello", "hello", "goodbye")]
[TestFixture("zip", "zip")]
[TestFixture(42, 42, 99)]
public class ParameterizedTestFixture
{
// .....
}
}
Then all tests work well in unity editor (still in play mode), but when i run tests in android platform, the following error occurred for every test:
No suitable constructor was found
How should i use parameterized test fixture in android platform?
7909018–1008397–ParameterizedTestFixture.cs (1.31 KB)
sbergen
February 19, 2022, 7:37am
2
This looks like it could be a code stripping issue, which happens because the constructor will be called through reflection. You could try adding [Preserve]
to the constructors to see if that would help.
Wow, Really thanks.
After adding [UnityEngine.Scripting.Preserve] attribute to all constructors, all tests passed in android platform.
But i am still curious about why i have to add namespace for parameterized test fixture?
1 Like
I came here to post about this after struggling about. I thought it was just that parameterised test fixtures were not supported, and that there was no documentation for this.
Completely surprised to find that it works when you put the test fixture under a namespace???
[Preserve] did not work for me, adding a the test class to a namespace fixed it.
I found this issue in nunit:
opened 12:09PM - 11 Jan 17 UTC
closed 11:58PM - 19 Jan 17 UTC
is:bug
closed:done
pri:normal
Following example will fail to build with :
```
[TestFixtureSource("FixtureArg… s")]
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 <filename unknown>:0
> at NUnit.Framework.Guard.ArgumentNotNullOrEmpty (System.String value, System.String name) [0x00000] in <filename unknown>:0
> at NUnit.Framework.Internal.Test..ctor (System.String pathName, System.String name) [0x00000] in <filename unknown>:0
> at NUnit.Framework.Internal.TestSuite..ctor (System.String parentSuiteName, System.String name) [0x00000] in <filename unknown>:0
> at NUnit.Framework.Internal.ParameterizedFixtureSuite..ctor (ITypeInfo typeInfo) [0x00000] in <filename unknown>:0
> at NUnit.Framework.Internal.Builders.DefaultSuiteBuilder.BuildMultipleFixtures (ITypeInfo typeInfo, IEnumerable`1 fixtures) [0x00000] in <filename unknown>:0
> at NUnit.Framework.Internal.Builders.DefaultSuiteBuilder.BuildFrom (ITypeInfo typeInfo) [0x00000] in <filename unknown>: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
```