Giter VIP home page Giter VIP logo

aspnetcorelearning's Introduction

Software Testing, very broad term to talk about. What we are going to discuss here

  • Basics
  • Automated testing using Unit tests and Integration tests specific to Web app using Aspnetcore3
  • Adding conventional test using Best.Conventional library
  • Using Bogus Library to create data for dev environment
  • How to manage in Memory database/Real database data for integration tests

All of the above using

  • aspnetcore
  • sql server
  • xUnit
  • Moq

Basics Naming I usually follow the guidelines given on MSDN while writing tests. It has nice examples of explaining the naming conventions.

I like the important note in the docs.

It's important to get this terminology correct. If you call your stubs "mocks", other developers are going to make false assumptions about your intent.

I would encourage give this article a read to get better understanding of Mocks and Stubs.

Dependency Injection

DI is one of the basic building blocks to enable components ready for testing.

Structure of each Test

  • Arrange
  • Act
  • Assert

These names are self explanatory, for each test we Arrange the data that need for the test then we act on the the SUT (System under test) and then we do assertions on the results.

Mocks

What do we need to mock?

  • Configuration
  • Database
  • Logger

Mocking configuration

var mockConfiguration = new Mock<IConfiguration>();
mockConfiguration.Setup(m => m[It.Is<string>(s => s == "ConfigurationKey")]).Returns(<ConfigurationValue>);

Database

We have configured the database as a service and we have the ability to use whatever database we like. I have setup 3 base classes to use 3 different databases. I can choose whichever database I like depending on the test.

  1. In Memory
  2. Sqlite
  3. SqlExpress

Setup We can follow the instructions given on MSDN to start setting up the integration tests for aspnetcore.

Above link will explain setup of the WebClient as well. So that we can make api calls similar to how we would do it from the client side.

References https://martinfowler.com/articles/mocksArentStubs.html

https://martinfowler.com/articles/practical-test-pyramid.html

https://blog.ploeh.dk/2013/10/23/mocks-for-commands-stubs-for-queries/

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.1

https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.1

https://github.com/dotnet/EntityFramework.Docs/tree/master/samples/core/Miscellaneous/Testing/TestProject

aspnetcorelearning's People

Contributors

karm435 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.