"PRO asp.ne MVC4 Study notes" using MOQ to assist with unit testing

Source: Internet
Author: User

Clear the problem:

First, when we do unit tests on a, we may find that the implementation of a must depend on B. At this point, when we write the unit test, we must first create an instance of B, and then pass B to a and then create an instance of a to test.

This will cause some problems:

1, our unit testing will become complex and fragile. It's complicated because we have to spend our energy figuring out the logic of B. Fragility is because if the logic of B changes, we may also face a failure in unit testing of a.

2, more importantly, when we failed in the test, we can not quickly locate whether it is a problem or B.

So we use the MOQ technique to mock "forge" an instance of B, so that we can focus on unit testing of a.

The next step is to record how MOQ is used.

"PRO asp.ne MVC4 Study notes" using MOQ to assist with unit testing

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.