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

[Template] Support for TUnit as testframework #1661

Open
samtrion opened this issue Jan 20, 2025 · 18 comments · May be fixed by #1662
Open

[Template] Support for TUnit as testframework #1661

samtrion opened this issue Jan 20, 2025 · 18 comments · May be fixed by #1662
Labels
documentation Improvements or additions to documentation investigate This issue require further investigation before closing.

Comments

@samtrion
Copy link
Contributor

With existing support for various testing frameworks, it would be great if the current offering could be extended with TUnit.

TUnit is a rising star that challenges existing test frameworks such as xUnit and NUnit. Especially in terms of simplified syntax and performance, it clearly stands out from the existing test frameworks without sacrificing familiar features.

@linkdotnet
Copy link
Collaborator

Hey @samtrion

Besides that we don’t offer templates for TUnit - is there anything missing or not working?
It should work without any problem (didn’t try it until now).

@samtrion
Copy link
Contributor Author

@linkdotnet Support as a template was meant when this issue was created.

Switching to TUnit can be done in 3 simple steps after creation. Therefore, there is not much to consider.

  1. mark all tests as [Test].
  2. remove reference to Microsoft.NET.Test.Sdk from the .csproj file
  3. adjust OutputType to <OutputType>Exe</OutputType> in the project file

After that it works without problems.

@samtrion samtrion changed the title Support for TUnit as testframework [Template] Support for TUnit as testframework, whi Jan 20, 2025
@samtrion samtrion changed the title [Template] Support for TUnit as testframework, whi [Template] Support for TUnit as testframework Jan 20, 2025
@samtrion
Copy link
Contributor Author

samtrion commented Jan 20, 2025

It should also be noted that there is an ambiguous reference between Bunit.TestContext and TUnit.Core.TestContext.

@linkdotnet
Copy link
Collaborator

We can add the template. And probably we will do this only for v2 of Bunit.

The whole TestContext name conflict will be a thing of the past as we rename it to BunitContext.

@linkdotnet
Copy link
Collaborator

We have to check how nice TUnit plays together with our templates, given that we use Microsoft.NET.Sdk.Razor. So there are multiple (custom) source code generators at work.

@samtrion
Copy link
Contributor Author

We have to check how nice TUnit plays together with our templates, given that we use Microsoft.NET.Sdk.Razor. So there are multiple (custom) source code generators at work.

I was just able to run a few tests with both the latest stable and the current 2 preview version. No noticeable problems so far

@linkdotnet
Copy link
Collaborator

Did you use the "classic" C# tests or tests written in razor files?

@samtrion
Copy link
Contributor Author

So far only classic tests

@linkdotnet linkdotnet added the investigate This issue require further investigation before closing. label Jan 20, 2025
@linkdotnet
Copy link
Collaborator

Short test from my side:

warning CS8892: Method 'TestingPlatformEntryPoint.Main(string[])' will not be used as an entry point because a synchronous entry point 'AutoGeneratedProgram.Main(string[])' was found.

Seems there is some work to do.

@samtrion
Copy link
Contributor Author

Short test from my side:

warning CS8892: Method 'TestingPlatformEntryPoint.Main(string[])' will not be used as an entry point because a synchronous entry point 'AutoGeneratedProgram.Main(string[])' was found.

Seems there is some work to do.

Shouldn't be a big problem

@linkdotnet
Copy link
Collaborator

linkdotnet commented Jan 20, 2025

Spicey! Thanks for the link

@linkdotnet
Copy link
Collaborator

One step further - have to try a bit more when I have more time.
Current state of affairs: It does compile, but doesn't discover any test.

@samtrion
Copy link
Contributor Author

samtrion commented Jan 20, 2025

One step further - have to try a bit more when I have more time. Current state of affairs: It does compile, but doesn't discover any test.

As mentioned here, or in my previous message

Switching to TUnit can be done in 3 simple steps after creation. Therefore, there is not much to consider.

  1. mark all tests as [Test].
  2. remove reference to Microsoft.NET.Test.Sdk from the .csproj file
  3. adjust OutputType to <OutputType>Exe</OutputType> in the project file

After that it works without problems.

And you have to adjust your IDE ...

@linkdotnet
Copy link
Collaborator

No that does work indeed. The problem seems the generated C# file from the razor code.
So something like:

@using Bunit
@using TUnit.Core;

@inherits Bunit.BunitContext

@code
{
    [Test]
    public void CounterStartsAtZero()
    {
        var cut = Render(@<Counter />);

        cut.Find("p").MarkupMatches(@<p>Current count: 0</p>);
    }
}

Will not have any discoverable test.

@linkdotnet
Copy link
Collaborator

PS: I am only using the CLI ATM

@linkdotnet
Copy link
Collaborator

The main issue with razor files is that they will be taken care of by the compiler, and C# files are generated.

As of now, a source code generator can not see or use the output of another generator. Somewhere on the roslyn repo there is an issue addressing exactly that. So, therefore, if people want to use TUnit, they might be locked in "csharp" only.

From the point of view of the template, that wouldn't be a big issue. And we have to document that somewhere in our docs.

@linkdotnet
Copy link
Collaborator

Using Microsoft.NET.Sdk.Razor will lead to such an output:

dotnet run

████████╗██╗   ██╗███╗   ██╗██╗████████╗
╚══██╔══╝██║   ██║████╗  ██║██║╚══██╔══╝
   ██║   ██║   ██║██╔██╗ ██║██║   ██║   
   ██║   ██║   ██║██║╚██╗██║██║   ██║   
   ██║   ╚██████╔╝██║ ╚████║██║   ██║   
   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝╚═╝   ╚═╝   
   
   TUnit v0.6.154.0 | 64-bit | Darwin 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec  6 18:56:34 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6020 | osx-arm64 | .NET 8.0.10 | Microsoft Testing Platform v1.4.3
   

Test run summary: Zero tests ran - bin/Debug/net8.0/test.dll (net8.0|arm64)
  total: 0
  failed: 0
  succeeded: 0
  skipped: 0
  duration: 59ms

While plain old cs files with Microsoft.NET.Sdk

████████╗██╗   ██╗███╗   ██╗██╗████████╗
╚══██╔══╝██║   ██║████╗  ██║██║╚══██╔══╝
   ██║   ██║   ██║██╔██╗ ██║██║   ██║   
   ██║   ██║   ██║██║╚██╗██║██║   ██║   
   ██║   ╚██████╔╝██║ ╚████║██║   ██║   
   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝╚═╝   ╚═╝   
   
   TUnit v0.6.154.0 | 64-bit | Darwin 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec  6 18:56:34 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6020 | osx-arm64 | .NET 8.0.10 | Microsoft Testing Platform v1.4.3
   
failed CounterStartsAtZero (186ms)
  Bunit.ElementNotFoundException: No elements were found that matches the selector 'p'

Basically a test is run

@linkdotnet linkdotnet added the documentation Improvements or additions to documentation label Jan 20, 2025
@linkdotnet
Copy link
Collaborator

I do have a version that might do the trick (C# only). @egil let's discuss this on Friday latest.

@linkdotnet linkdotnet linked a pull request Jan 20, 2025 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation investigate This issue require further investigation before closing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants