Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Feb 24 20:41
    egil opened #333
  • Feb 23 09:31
    egil closed #303
  • Feb 22 10:11
    egil edited #329
  • Feb 22 10:07
    egil edited #329
  • Feb 22 09:34
    codecov[bot] commented #328
  • Feb 22 09:34
    codecov[bot] commented #328
  • Feb 22 08:51
    codecov[bot] commented #328
  • Feb 22 08:21
    codecov[bot] commented #328
  • Feb 21 14:00
    codecov[bot] commented #328
  • Feb 21 14:00
    egil synchronize #328
  • Feb 21 13:58
    codecov[bot] commented #328
  • Feb 21 13:56
    codecov[bot] commented #328
  • Feb 21 13:56
    egil synchronize #328
  • Feb 21 11:23
    codecov[bot] commented #328
  • Feb 21 11:23
    egil synchronize #328
  • Feb 21 09:23
    egil synchronize #303
  • Feb 21 09:20
    egil commented #303
  • Feb 21 09:18
    egil synchronize #303
  • Feb 21 09:18
    egil synchronize #303
  • Feb 21 09:14
    egil synchronize #303
HellfireGaming
@HellfireGaming4_twitter
I thought this was strange in the tutorial as well
Egil Hansen
@egil
if you reverse it, e.g. dotnet add MyTests.csproj reference MyComponent.csproj it works, right?
HellfireGaming
@HellfireGaming4_twitter
no it doesn't it still gives me the issue that it cant find the component
Egil Hansen
@egil
thats weird.
HellfireGaming
@HellfireGaming4_twitter
I couldn't find any mention of this issue anywhere
Egil Hansen
@egil
what you need to do is to make sure your components project is referenced by your test project. When you do that, the tests should be able to reference your components.
this is just basic C#/.net functionality, so if it doesnt work, there is something weird going on, on your computer.
let me just try things locally and get back to you
HellfireGaming
@HellfireGaming4_twitter
a component project in this sense is just the project that hosts your components right?
Egil Hansen
@egil
yes, it can be a blazor component library, a blazor server project, or a blazor wasm project.
HellfireGaming
@HellfireGaming4_twitter
okay
then that should be fine I'm using a blazorr server project
Egil Hansen
@egil
you are right though, there is a mistake in the tutorial
image.png
Just confirmed that this work:
Egil Hansen
@egil
This was created like so:
mkdir MyExample
cd .\MyExample\
dotnet new sln
dotnet new razorclasslib -o Lib
dotnet new bunit -o LibTests
dotnet sln .\MyExample.sln add .\Lib\
dotnet sln .\MyExample.sln add .\LibTests\
dotnet add .\LibTests\LibTests.csproj reference .\Lib\Lib.csproj
In there it is possible to reference components in Lib from LibTests
hope this helps
and thanks for spotting the mistake in the docs!
HellfireGaming
@HellfireGaming4_twitter
thanks
so then the LibTests holds the components in this example??
Egil Hansen
@egil
They are updated and should be published in 5 minutes
No, LibTests references Lib that has the component
LibTests comes with a dummy component just to include a test that can run
when using the bunit template, you can delete the counter.razor and countertest.cs files
HellfireGaming
@HellfireGaming4_twitter
yes I see this works as I imagined it, thanks
Egil Hansen
@egil
image.png
Here is an example of a test
HellfireGaming
@HellfireGaming4_twitter
yeah I moved the Counter.razor file to the Lib project and added a using Lib in the CounterTest to check if it worked
do both projects need the same <Project Sdk="Microsoft.NET.Sdk.Razor">?
Egil Hansen
@egil
Only if you plan to write tests in .razor files.
HellfireGaming
@HellfireGaming4_twitter
if I run dotnet new blazorserver this will create a project using <Project Sdk="Microsoft.NET.Sdk.Web"> and changing this to <Project Sdk="Microsoft.NET.Sdk.Razor"> will give errors
Egil Hansen
@egil
ah, you do not have to change that
bunit doesnt care what the lib hosting the components are
but if you want to write tests using razor syntax (https://bunit.egilhansen.com/docs/getting-started/writing-razor-tests.html) then the test lib needs to be Microsoft.NET.Sdk.Razor to get the blazor compiler incldued.
HellfireGaming
@HellfireGaming4_twitter
okay I may need to redo my setup to make it work I still get the same issue in my blazorserver example but I probably made some changes I'm unaware of
HellfireGaming
@HellfireGaming4_twitter
I tried running these commands
mkdir MyExample
cd .\MyExample\
dotnet new sln
dotnet new blazorserver -o Lib
dotnet new bunit -o LibTests
dotnet sln .\MyExample.sln add .\Lib\
dotnet sln .\MyExample.sln add .\LibTests\
dotnet add .\LibTests\LibTests.csproj reference .\Lib\Lib.csproj
but this will give me the issue of not finding the component, F:\Projects\MyExample\LibTests\CounterCSharpTest.cs(19,39): error CS0246: The type or namespace name 'Counter' could not be found (are you missing a using directive or an assembly reference?) [F:\Projects\MyExample\LibTests\LibTests.csproj]
Egil Hansen
@egil
Thats weird
It works for me.
I deleted the Counter.razor in the test project
Then in CounterCSharpTests I add a using Lib.Pages;
then it find the Counter.razor component/page in the Lib project
HellfireGaming
@HellfireGaming4_twitter
let me try that I figured I was doing something wrong with the namespace
yes that does work fine thanks
Egil Hansen
@egil
unless you use the @namespace Foo.Bar syntax in .razor files, the namespace is based on the folder structure.
Egil Hansen
@egil
So for anybody wondering if NET6 preview 1 works with bUnit, the answer seems to be yes. At least the very basic example I just tried. This seems to be all that is needed for a xunit/bunit project:
<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.0-preview.1.21103.6" />
    <PackageReference Include="bunit.web" Version="1.0.0-preview-01" />
    <PackageReference Include="bunit.xunit" Version="1.0.0-preview-01" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="1.3.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>
Egil Hansen
@egil
Hi all, going live in 15 minutes on twitch.tv/egilhansen with more TDDing of the Blazing Pizza Workshop. This stream will follow up on the refactor of the fake pizza API we did, so this time it should be more progress and less refactoring. See you soon on stream!