bUnit bUnit
Search Results for

    Show / Hide Table of Contents

    Mocking or faking component dependencies

    Mocking or faking a component under test's dependencies (services) can be the difference between being able to write a stable test that is easy to understand, and the opposite. bUnit does not have any particular preferences when it comes to mocking frameworks; all the usual suspects will work with bUnit. For example, Moq, JustMock and NSubstitute all work well with bUnit, so pick the one you are the most comfortable with and use it.

    bUnit does, however, come with a few specially crafted test doubles for some of Blazor’s built-in services. These are designed to make it easy to write tests of components that uses these services. More are planned for the future too.

    The built-in test doubles are described on the following pages:

    • Faking authentication and authorization
    • Emulating IJSRuntime
    • Mocking HttpClient
    • Faking persistent component state
    • Faking NavigationManager
    • Faking IWebAssemblyHostEnvironment
    • Uploading files to the InputFile component

    Premium sponsor: Progress Telerik.

    Editorial support provided by Packt.

    Supported by the .NET Foundation.

    • Improve this Doc
    Back to top Documentation updated on 12/20/2022 19:57:41 +00:00 in commit e961bf7d62.