Clean Testing Architecture - Subcutaneous Tests

 

 

 测试金字塔:

 

 

 

 

 if logic exits in asp.net core, we could write some really cool asp.net core integration tests.

Clean Testing:

 

 

 Subcutaneous tests -

  • they are not going to test anything on the UI, it will give us that higher level of confidence that we want.
  • It's a test that operates just below the UI, tests the basic inputs and outputs of the system. Idea if you keep lotic out of the UI, reduce the need for UI tests.
  • Easy to write and easy to maintain.
  • Test commands and queries
  • Include internal services
  • Mock external services
  • Keep it sample

 

 

Presentation - UI, backend apis

Core - Application, domain layer, commands, queries, entities, repositories, validators, mapping configuration a whole host of things

Infrastructure - Internal(database), external infrasture.

.net core

Testing Frameworks: Xunit, nunit and MSTest, fixie.

Assertion:

  1. FluentAssertions
    • Naturally specify the outcome of a automated test
    • Improved readability within tests(better assertions)
    • Clearly explains test failure results(better test results)
    • Helps to reduce the need to debug tests
    • overall, improves productivity and simplifies approach
  2. Moq
    • Mocking framework for .net
    • Very popular and friendly(according to repo)
    • Supports mocking classes and interfaces
    • Strongly typed(so no magic strings)
    • Simple to use, no prior knowledge required
  3. EF Core InMemory (not recommended)
    • Build-in database provider
    • Uses in-memory database
    • Built for testing purposes
    • No overhead of I/O operations
    • Lighweight with minimal dependencies
  4. Respawn
    • Intelligent database cleaner for integration tests
    • Instead of deleting data or rolling back transactions
    • Resets database to a clean checkpoint
    • Ignore tables/schemas, e.g. _EFMigrationsHistory
    • Supports SQL server, Postgres, MySQL,...

 

 

posted @ 2021-01-05 16:44  荣珠  阅读(50)  评论(0)    收藏  举报