ASP. NET zero--Unit test

Source: Internet
Author: User

Unit Test

The ASP. NET Zero startup project contains unit and integration tests. Use the following tools to develop your tests:

    • XUnit as a test framework.
    • shouldly as the assertion library.
    • Microsoft.EntityFrameworkCore.InMemory Entity Framework and database.
    • Abp.testbase simplifies integration testing of ABP-based applications.

Testing Covers The project's Domain (CORE) and application tiers. Open Test Explorer (test \ Windows \ Test Explorer in the VS Main menu) to run unit tests:

Some unit tests (tenant authoring, version creation, and so on) are only available for multi-tenancy concepts. You can change the abpzerotemplateconsts.multitenancyenabled to False to make your application a single tenant. Therefore, the tests associated with multi-tenancy will be skipped.

These unit tests will be a guide to understanding the code. In addition, they can be used as your application functionality to write your own unit test model.

All unit test classes (actually integration tests, because they are integrated into libraries used by Abp,entityframework,automapper and other application tiers) are from Apptestbase derived from it . It initializes the ABP system, uses the effort simulation database, creates initial test data for each test, and logs on to the application. It also provides some useful and common methods for all tests.

Here, the sample unit tests in the application:

Publicclass userappservice_delete_tests:userappservicetestbase{[Fact] public async Task should_delete_user () {//arrange createtestusers (); var user = await getuserbyusernameornullasync (" artdent "); User. SHOULDNOTBE (null); //act await userappservice.deleteuser ( new idinput<long> (user. ID)); //assert user = await Getuserbyusernameornullasync ( "artdent"); User. Isdeleted.shouldbe (true);}          

it creates some users to test, and then verifies that there is a user named "Artdent". then call the DeleteUser method of the User application service (being tested) . Finally, check to see if the user is deleted. Here, user is a soft-deleted entity, so if it is deleted , its IsDeleted property must be true.

You can read this article to better understand unit testing.

Publish to IIS

If you want to publish the solution to IIS, check the documentation for Microsoft .

ASP. NET zero--Unit test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.