Code Monkey home page Code Monkey logo

apitestingaz's Introduction

Testing .NET Web APIs from A to Z

This is the demo solution used in the talk "Testing .NET Web APIs from A to Z".

You built an API in .NET, put it in production, customers are using it, and now you have promises to keep. Promises related to the API contract and behavior. A good test suite will help you keep those promises by protecting against regressions. It will allow you to quickly iterate, add new features and expand the API if it is resistant to refactoring and is giving fast feedback.

This session is about how to build such a test suite. We will discuss and showcase how to verify the API contract, the API’s behavior, and cross-cutting concerns like authentication and authorization. We will cover the pros/cons of various approaches regarding test runtime, coverage, and usage of test doubles vs. end-to-end testing using real data stores, among other things.

-- https://sessionize.com/s/egil/testing-.net-web-apis-from-a-to-z/68735

The demo solution showcases the following:

  1. Using Alba, a wrapper around WebApplicationFactory, to configure and run the API under test.

    1. How to create custom assertions that integrates nicely with Albas existing assertions. The custom assertions leverage semantic comparison of JSON returned from the API endpoints, resulting in more maintainable tests.

    2. How to create custom reusable extensions which customizes the API. In particular, it includes a LocalTestDatabaseAlbaExtension and TimeProviderAlbaExtension extensions.

  2. Using Verify for snapshot testing of content returned the API under test.

    1. How to customize Verify to perform capture and comparison differently. In particular, Verify is customzied to perform semantic comparison of JSON instead of string based comparison for more maintainable tests.

    2. How to create custom file converter that takes Alba's IScenarioResult type and generate a JSON document that can be verified using snapshot testing.

  3. How to create xUnit test collections that span multiple test classes and custom test fixtures that are shared by the collection (ApiTestCollection, TodoApiFixture).

  4. How to create a base class that encapsulates pre- and post-test run operations (TodoApiTestBase).

Requirements

To run the demo solution locally, you will need the following:

  • .NET 8 SDK
  • SQL Server LocalDB instance

apitestingaz's People

Contributors

egil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.