Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TestFixtureAttributeExamples.cs To give an example of using params in a constructor #807

Merged
merged 7 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/articles/nunit/writing-tests/attributes/testfixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ list of categories.

### Example

The following test fixture would be instantiated by NUnit three times,
The following test fixture would be instantiated by NUnit five times,
passing in each set of arguments to the appropriate constructor. Note
that there are three different constructors, matching the data types
provided as arguments.
that there are four different constructors, matching the data types
provided as arguments, and the params keyword can be used to allow
passing different numbers of arguments.

[!code-csharp[MultipleParameterizedTestFixtures](~/snippets/Snippets.NUnit/Attributes/TestFixtureAttributeExamples.cs#MultipleParameterizedTestFixtures)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class TestFixtureAttributeExamples
[TestFixture("hello", "hello", "goodbye")]
[TestFixture("zip", "zip")]
[TestFixture(42, 42, 99)]
[TestFixture('a', 'a', 'b')]
[TestFixture('A', 'A')]
public class ParameterizedTestFixture
{
private readonly string _eq1;
Expand All @@ -37,6 +39,17 @@ public ParameterizedTestFixture(int eq1, int eq2, int neq)
_neq = neq.ToString();
}

// Can use params arguments (but not yet optional arguments)
public ParameterizedTestFixture(params char[] eqArguments)
{
_eq1 = eqArguments[0].ToString();
_eq2 = eqArguments[1].ToString();
if (eqArguments.Length > 2)
_neq = eqArguments[2].ToString();
else
_neq = null;
Shiney marked this conversation as resolved.
Show resolved Hide resolved
}

[Test]
public void TestEquality()
{
Expand Down Expand Up @@ -162,4 +175,4 @@ public void TestMyArgTypes(T1 t1, T2 t2)
}
}
#endregion
}
}