NUnit Unit Test Practice

Source: Internet
Author: User

Project often encountered such a problem, the written module, due to changes in the requirements of the database field has been modified, the logic has some changes, so, in a large number of code changes, run the interface to start testing. Helpless at once cannot write to all logic, or even misspelled characters. Especially when doing B/s system, debugging a good function, often cost you a lot of time. And, if there are any changes, you have to do it again, and if you encounter some relationship, the debugging test is more complicated. And, after the project has done n modules, and modified a function, to tell the truth, God knows other logic whether the bug has not, hehe.

Therefore, the introduction of unit testing is very necessary, reasonable use, or can improve the quality of the code. The seemingly code-time extension, in fact, greatly shortens the debug time and greatly reduces the marginal corresponding of the modification function affecting other methods.

What if it's a better practice?

Generally we all use NUnit, this is not difficult, any garden inside, the Internet can search a lot of introductory articles, I do not repeat. Just talk about matters of caution.

1. Testing only the logical operation of the test, data crud test on the line. The collection of front-end UI data is not nunit. Our task is to ensure that the data passed to the UI is correct.

As shown in the standard demo, I only tested the BLL and DAL layers.

2. Test the database the best peaceful use of the database separate, because the usual test data and can not be very good to solve the problem of automated testing, as shown above, with app.config separate library configuration (demo with the same library)

3. The test data is constructed and cleaned according to the situation

Sometimes the data needs to be cleaned up, but sometimes it is not necessary, because the classification test, some data retention is more convenient, therefore, try to use [Test,category ("XX")] to classify

4. According to the module to test to improve efficiency and test results

Through the classification test, it is easier to see the problem of a module, sometimes, the individual test of a method of data does not indicate what the problem

5. Combined with testdriven.net to make you more effort, combined with this kind of vs add-in tools, testing became more convenient, NUnit became a device, basically open he is to see the green progress bar to cool.

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.