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

New test framework support #1295

Open
thomhurst opened this issue Sep 15, 2024 · 11 comments
Open

New test framework support #1295

thomhurst opened this issue Sep 15, 2024 · 11 comments

Comments

@thomhurst
Copy link
Contributor

Is the feature request related to a problem

I've been building a new testing framework for .NET and noticed that you've got specialised packages for the existing major test frameworks. Would I or yourselves need to do anything to support my framework?

Describe the solution

New packages for TUnit

My framework can be found here: https://github.com/thomhurst/TUnit

@SimonCropp
Copy link
Member

i can take a look

first question is how do i access the current test parameter values from the static context? the other test frameworks use an async local to give access

@thomhurst
Copy link
Contributor Author

thomhurst commented Sep 16, 2024

i can take a look

first question is how do i access the current test parameter values from the static context? the other test frameworks use an async local to give access

Thanks @SimonCropp . You can access this via:

TestContext.Current!.TestDetails.TestMethodArguments

@SimonCropp
Copy link
Member

@thomhurst as much a think strong naming adds no value, it will negatively impact the uptake of TUnit

@thomhurst
Copy link
Contributor Author

@thomhurst as much a think strong naming adds no value, it will negatively impact the uptake of TUnit

Sorry what do you mean?

@SimonCropp
Copy link
Member

tunit is not strong named. most potential consumers will want it to be strong named

@thomhurst
Copy link
Contributor Author

Ohhh you mean key signing the assembly/package? Thanks for the heads up. I'll raise an issue on my repo so I don't forget about it :)

@SimonCropp
Copy link
Member

this is some nunit code

[TestFixtureSource(nameof(FixtureArgs))]
public class TestFixtureSourceAndTestCaseUsage(string arg1, int arg2)
{
    [TestCase("FromTestCase2")]
    public Task Test(string arg3) =>
        Verify(
            new
            {
                arg1,
                arg2,
                arg3
            });

    static object[] FixtureArgs =
    [
        new object[]
        {
            "Value2",
            2
        }
    ];
}

whats the equivalent in TUnit?

@SimonCropp
Copy link
Member

this


    [Test]
    [Arguments((float)1.1)]
    public Task Float(float arg) =>
        Verify(arg);

results in

33>Float_ParametersSample_49363d0d3fb0455cb46335bd8b7587a2.Generated.cs(18,39): Error CS0664 : Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type

if i use

    [Test]
    [Arguments(1.1F)]
    public Task Float(float arg) =>
        Verify(arg);

i get

33>Float_ParametersSample_096a4f03ccd54ee285b352b9f622e9ee.Generated.cs(18,39): Error CS0664 : Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type

@thomhurst
Copy link
Contributor Author

whats the equivalent in TUnit?

[MethodDataSource(nameof(FixtureArgs), UnfoldTuple = true)]
public class TestFixtureSourceAndTestCaseUsage(string arg1, int arg2)
{
    [Test]
    [Arguments("FromTestCase2")]
    public Task Test(string arg3) =>
        Verify(
            new
            {
                arg1,
                arg2,
                arg3
            });

    public static (string, int) FixtureArgs() => ("Value", 2);
}

@thomhurst
Copy link
Contributor Author

thomhurst commented Sep 16, 2024

this


    [Test]
    [Arguments((float)1.1)]
    public Task Float(float arg) =>
        Verify(arg);

results in

33>Float_ParametersSample_49363d0d3fb0455cb46335bd8b7587a2.Generated.cs(18,39): Error CS0664 : Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type

if i use

    [Test]
    [Arguments(1.1F)]
    public Task Float(float arg) =>
        Verify(arg);

i get

33>Float_ParametersSample_096a4f03ccd54ee285b352b9f622e9ee.Generated.cs(18,39): Error CS0664 : Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type

Ah nice spot - My bad! Source generator wasn't appending the relevant suffix.

Can you try with version 0.1.738?

@thomhurst
Copy link
Contributor Author

Thanks @SimonCropp ! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants