Can we use bUnit inside Microsoft.NET.Sdk.BlazorWebAssembly project ? #1164
Replies: 3 comments
-
To execute/run unit tests, you need to pick a testing framework like xUnit. Then, together with bUnit, you can render components and assert against them. There are some hacky workarounds (msbuild trickery) to mix test code with production code in the same project, but it's not a common thing to do in the .net ecosystem, because you typically don't want your test files deployed to production, so there is also going to be a lot of fighting with the various frameworks and libraries to get it working. In other words, it's probably not what you want. |
Beta Was this translation helpful? Give feedback.
-
Yup,
I can exclude the files and framework from production deployment.
Just it is convenient to find test file for component and easy to work when
implementing TDD approach.
Can we use bunit with xunit in Microsoft.NET.Sdk.BlazorWebAssemblyproject
or not ?
…On Sun, Jul 30, 2023, 00:26 Egil Hansen ***@***.***> wrote:
Run run unit tests, you need to pick a testing framework like xUnit. Then,
together with bUnit, you can render components and assert against them.
There are some hacky workarounds (msbuild trickery) to mix test code with
production code in the same project, but it's not a common thing to do in
the .net ecosystem, because you typically don't want your test files
deployed to production, so there is also going to be a lot of fighting with
the various frameworks and libraries to get it working.
In other words, it's probably not what you want.
—
Reply to this email directly, view it on GitHub
<#1164 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD56CNQB5XN5T563WYATLL3XSUMRBANCNFSM6AAAAAA24QSTXI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Yes you can use bUnit with xUnit. Check out https://bunit.dev/docs/getting-started/create-test-project.html?tabs=xunit |
Beta Was this translation helpful? Give feedback.
-
I would like to create Unit tests of the razor component inside the same folder as that component.
For eg. counter. razor, counterTests.razor.
I don't want to create another project for unit testing. Is this possible with Bunit?
As the document states Make sure the test project has the SDK type set to Microsoft.NET.Sdk.Razor. Otherwise, the Blazor compiler will not translate your .razor files into runnable code.
Beta Was this translation helpful? Give feedback.
All reactions