Aspnetcore: Unit test framework for Blazor

Created on 25 Jan 2018  路  12Comments  路  Source: dotnet/aspnetcore

  • [ ] Unit test helper for instantiating components and trying out events, etc.
  • [ ] End-to-end
Components Big Rock area-blazor enhancement

Most helpful comment

Please also consider snapshot testing, similar to Jest. I've been using it with Vue.js and I've found it to be a great way to test UI without being too fragile and needing constant fixing.

All 12 comments

Please also consider snapshot testing, similar to Jest. I've been using it with Vue.js and I've found it to be a great way to test UI without being too fragile and needing constant fixing.

Probably under consideration, but it appears the end-to-end tests could work with Puppeteer.Sharp (ping @kblok, the Selenium libraries are also an option) using something like Razor Live Reload with the usual ways of starting a web server in tests. Then have examples how to collect performance numbers, test some CSS driven things, web components and Service Workers. Could be interesting to load tests dynamically so one could test mobile browsers too (especially performance).

Cypress and TestCafe could be some examples, albeit I'm not sure how much overlap there are with assertion libraries, like XUnit.

<Edit: One consideration is also isomorphic situations, one being something that can be run or mimicks environments like Cloudflare Workers, e.g. https://github.com/anywhichway/dexterous or https://github.com/envato/cloudflare-worker-test-harness .

Question: is this for publishing Microsoft.AspNetCore.Components.Testing?

@RehanSaeed just an FYI, I maintain a snapshot style testing lib https://github.com/SimonCropp/Verify. and i am actively tracking blazor testing to see if i can add any specific value to that scenario. Happy to accept any suggestions you have

Hi folks. At this point, we think providing testing framework support for Blazor is something that can best be handled by the Blazor open-source community. The bUnit project, for example, already provides support for unit testing components and implements many of the implementation ideas that we were exploring. Instead of building and supporting our own test framework, we prefer to encourage community innovation in this space, which allows us to focus our efforts on core framework improvements. Given this decision, I'm going to go ahead and close this issue.

FWIW i think this is a mistake. if you dont explicitly design for things to be testable (from an application perspective) then result will not be testable. and having the only test frameworks as downstreams means they will be too disconnected from you design process to give timely feedback.

If you don't explicitly design for things to be testable (from an application perspective) then result will not be testable. and having the only test frameworks as downstreams means they will be too disconnected from your design process to give timely feedback.

We certainly agree that Blazor needs to be designed to be testable, and we do consider testability in our design process. We of course welcome feedback in this area! As for whether test framework authors would be able to give us feedback in a timely fashion on design decisions, I think that should be possible by us continuing to do design and development in the open and also shipping frequent preview releases.

how about inviting the bunit team to merge projects and join the core blazor team

I think the disconnect is already apparent. eg the absence of testing from docs https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started?view=aspnetcore-3.1&tabs=visual-studio and many (other wise very complete) samples eg
https://github.com/dotnet-presentations/blazor-workshop

i was so looking forward to microsoft's own blazor testing framework (especially after i saw it included in the recently published roadmap).

is the bUnit project going to at least be a .Net Foundation supported project?
right now, it seems like mostly a one person project and i'm afraid of that kind of uncertainty

@SimonCropp We do have documentation gap on how to do component unit testing with Blazor. We've been tracking adding it for a while (https://github.com/dotnet/AspNetCore.Docs/issues/10747), but we wanted to decide first whether we would be building a test framework or not (this issue). Now that we've decide to go with the existing community solutions, we've already started talking to the bUnit project owner about adding this content both to the docs and to the Blazor workshop. I don't think this reflects a disconnect with these community projects - it just reflects limited time and resources.

@githubfanster I brought this up with the bUnit owner earlier today as well. The thinking is that we will wait until bUnit hits 1.0, and then start the submission process.

@SimonCropp if time allows, I will contribute docs about testing and a lab to the Blazor Workshop, but as @githubfanster noticed, I'm just one person, so right now I am prioritizing getting bUnits own docs up to date for the beta-7 release.

@githubfanster I do want to move the project into the .net foundation as soon as possible. And I also welcome any form of help I can get with the project.

Was this page helpful?
0 / 5 - 0 ratings