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