AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

How to Unit Test SignalR

Open BlueDragon709 opened this issue 6 years ago • 20 comments

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:

  • Prerequisites
  • Testing hubs -- Using MSTest -- Using NUnit -- Using xUnit
  • Testing groups -- Using MSTest -- Using NUnit -- Using xUnit
  • Examples

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

BlueDragon709 avatar Feb 22 '19 09:02 BlueDragon709

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.

NightAngell avatar Feb 25 '19 16:02 NightAngell

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

Kiril1512 avatar Nov 07 '19 09:11 Kiril1512

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

chrispickford avatar Feb 16 '21 14:02 chrispickford

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

DennisvanBeelen avatar Mar 11 '21 13:03 DennisvanBeelen

+1 Any news on this?

ivanrodriguezfernandez avatar Mar 18 '21 10:03 ivanrodriguezfernandez

+1

segadora avatar Jun 29 '21 06:06 segadora

+1

jacekkulis avatar Jul 16 '21 13:07 jacekkulis

+1

petercwq avatar Feb 03 '22 22:02 petercwq

+1

KeithBrio avatar Mar 28 '22 17:03 KeithBrio

+1

kacper-swoop avatar Mar 30 '22 06:03 kacper-swoop

Any update Code Maintainers?

HaroonSaid avatar May 17 '22 22:05 HaroonSaid

We would find this very useful as well

mkstephenson avatar Jul 15 '22 13:07 mkstephenson

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

Diomedes1990 avatar Jul 28 '22 15:07 Diomedes1990

+1

fn-bruce avatar Jul 29 '22 19:07 fn-bruce

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

sankarbha avatar Sep 29 '22 10:09 sankarbha

Any update ?

postmeback avatar May 11 '23 10:05 postmeback

any updates?

eranbar avatar Jun 20 '23 04:06 eranbar

Any update?

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

WeihanLi avatar Dec 27 '23 05:12 WeihanLi

+1

DomenPigeon avatar Jan 21 '24 22:01 DomenPigeon