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

Breaking: Respect NUnit class level parameters and drop support for custom TestName #1249

Merged
merged 28 commits into from
Jul 20, 2024

Conversation

SimonCropp
Copy link
Member

@SimonCropp SimonCropp commented Jul 17, 2024

Who is effected

  • NUnit users who are using a parameterised TestFixture
  • NUnit users who are using TestCase.TestName

Changes:

No longer respect TestFixture.TestName and `TestCase.TestName

Reasons

  • NUnit does not enforce uniqueness for these names. Which can result in difficult to diagnose file conflicts in received and verified files.
  • Prevents received and verified files for a specific test class or test method from being group together.
  • NUnit provides no way to reliably get TestName, resulting in Verify needing to guess the name using some string manipulation

Respect fixture level parameters and ignore NUnit fixture name convention

Previoulsy fixture level parameters were properly not respected by Verify. Verify would rely on NUnit convention for the fixture name. For example

[TestFixture("2", TestName = "CustomClassName")]
public class ClassLevelParams(string classParam)

The NUnit fixture name would be ClassLevelParams(1). While unique enough for the verified file it has several problems

  • Does not convey the parameter name in the resulting file
  • Make the Handling of TestFixture parameters inconsistent with TestCase parameters
  • Does not match the Verify convention of paramName=paramValue
  • Is incompatible with several Verify features. For example Ignore parameters for verified filename and NameForParameter

Sample

[TestFixture("1")]
[TestFixture("2", TestName = "CustomClassName")]
public class ClassLevelParams(string classParam)
{
    [TestCase("3")]
    [TestCase("4", TestName = "CustomClassName")]
    public Task Test(string methodParam) =>
        Verify("Value");

Result

Before

ClassLevelParams(1).CustomClassName_methodParam=4.verified.txt
ClassLevelParams(1).Test_methodParam=3.verified.txt
CustomClassName.CustomClassName_methodParam=4.verified.txt
CustomClassName.Test_methodParam=3.verified.txt

After

ClassLevelParams.Test_classParam=1_methodParam=3.verified.txt
ClassLevelParams.Test_classParam=1_methodParam=4.verified.txt
ClassLevelParams.Test_classParam=2_methodParam=3.verified.txt
ClassLevelParams.Test_classParam=2_methodParam=4.verified.txt

Migration

After upgrading, the recommended approach is to treat the old verified files as Orphaned verified files.

@SimonCropp SimonCropp changed the title Use named class level parameters Respect NUnit class level parameters Jul 19, 2024
@SimonCropp SimonCropp changed the title Respect NUnit class level parameters Respect NUnit class level parameters and drop support for custom TestName Jul 19, 2024
@SimonCropp SimonCropp changed the title Respect NUnit class level parameters and drop support for custom TestName Breaking: Respect NUnit class level parameters and drop support for custom TestName Jul 19, 2024
@tom-englert
Copy link
Contributor

👍 ❤️

@SimonCropp SimonCropp added this to the 26.0.0 milestone Jul 20, 2024
@SimonCropp SimonCropp merged commit 0fc72c2 into main Jul 20, 2024
5 checks passed
@SimonCropp SimonCropp deleted the use-named-class-level-parameters branch July 20, 2024 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants