Unit test - Test your .NET code (2) using NMOCK

xiaoxiao2021-03-06  45

Understanding the difficulties in unit testing

Before conducting the journey of the example code written for this article, it is necessary to understand the following challenge: There is a complex dependence collection of the library of unit testing. Although it is best to design a library with minimal dependencies, it is sometimes unrealistic, especially when the library is designed, not taken into account. These dependencies may require difficult or cost-effective, and may have trouble-time, which may require difficult or time to bring trouble to test processes. Consider an commercial logic library that uses data access components that require communication with the database server, as shown below.

Although business logic libraries and data access components are based on interface binding, commercial logic libraries still need to access the properties and methods provided by the data access component in unit tests, and there is difficulties in this.

Data Access Components require a connection to the database. This means that you need to configure components to connect the correct database and you almost certainly need to create a database test instance, so you have to risk the risk of product databases in the test. If you use SQL Server 2000, this may also be a controllable task, but if the data access component provides a large-scale database access? In the later circumstances, the test example of establishing a database is largely unrealistic. Even use SQL Server, time may be a factor in suppressing tests.

However, in this case, the data access layer of the configuration test is not the only difficulty. If your data access component is part of the project you have developed, it may not even exist, and even if it exists, it is still very likely to be in the development of many known or unknown bugs. In this case, you still have risks that even if the test code does not have a defect, but the unit test is not passed due to the BUGS that may occur in the data access layer. That is to say, in this case, the library to be tested is not completely independent from other modules, so the test is no longer the unit test at this point.

转载请注明原文地址:https://www.9cbs.com/read-79449.html

New Post(0)