dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.63k stars 25.3k forks source link

How to Unit Test SignalR #11052

Open BlueDragon709 opened 5 years ago

BlueDragon709 commented 5 years ago

Doc request for unit testing signalr in a ASP.NetCore 2.2 app I am currently working on a signalr application and I want to be able to test my hubs. I couldn't find any information about unit testing signalr in AspNetCore/SignalR. The only information that i could find was from 2013 for AspNet/SignalR and is pretty outdated.

I am sugesting to put the topic about unit testing signalr on this location:

Docs/ASP.NET/ASP.NET Core/ASP.NET Core 2.2/Real-time apps/Unit testing or Docs/ASP.NET/ASP.NET Core/ASP.NET Core 2.2/Test, debug and roubleshoot/Unit testing/signalr hubs

This topic will cover the following topics: Testing of hubs, testing of groups and examples.

A rough outline:

I hope this gets added because there is not a lot of information on this topic.

NightAngell commented 5 years ago

I wrote lib (available via nuget) which provide support for unit testing in signalR core (both Hub (Hub<T>) and IHubContext<T> (IHubContext<T, P>) ). I wrote docs for it too then if you want you can easily use it. In short summary it provide preconfigured mocks which are auto set upped by testing framework (NUnit, xUnit, MsTest, but there is also info how to use it with custom testing framework in docs) and some helpful 'verify' methods. For testing hubs you need just add nuget to your project and inherit from provided by lib base class (there is also possibility to use it without base class, info in docs). I don't want duplicate docs, then if you are interested:

  1. Project site
  2. Docs

There are examples in docs too.

Kiril1512 commented 5 years ago

Yes, this would be very helpful for developers not only for testing, but also do understand better SignalR through unit tests.

chrispickford commented 3 years ago

Adding my +1 as unit testing documentation would be extremely helpful.

DennisvanBeelen commented 3 years ago

Yes especially te proper way to mock Hubs and Clients would be super usefull.

ivanrodriguezfernandez commented 3 years ago

+1 Any news on this?

segadora commented 3 years ago

+1

jacekkulis commented 3 years ago

+1

petercwq commented 2 years ago

+1

KeithBrio commented 2 years ago

+1

kacper-swoop commented 2 years ago

+1

HaroonSaid commented 2 years ago

Any update Code Maintainers?

mkstephenson commented 2 years ago

We would find this very useful as well

Diomedes1990 commented 2 years ago

yes, this would be great, I was trying with old documentation.

fn-bruce commented 2 years ago

+1

sankarbha commented 2 years ago

yes, pl. share any documentation or sample unit test projects. Thanks.

postmeback commented 1 year ago

Any update ?

eranbar commented 1 year ago

any updates?

WeihanLi commented 10 months ago

Any update?

Hope for the unit testing support not only for the server but also for the client

DomenPigeon commented 9 months ago

+1

Kurren123 commented 3 weeks ago

+1