Vs Common Unit Test Problems and Solutions

Source: Internet
Author: User

Recently, I wrote some unit tests for a Web Service developed by vs. Although some test teams will do the test, it will bring convenience to the subsequent development work to do the unit test for the functional module.

 

The following are some problems and solutions encountered in vs unit test:

VS can use a third-party tool for unit test. I want to discuss it with the unit test project that comes with.

 

Question 1:
In the WEB Project, Web. config cannot be read in the unit test project. How can this problem be solved?

Solution:
1. You can create app. config for unit test and copy the content of web. config to app. config. Disadvantage: Remember to modify app. config every time you modify web. config.
2. use the app. put the config file in the bin \ debug or bin \ realtasks folder of the current test project and change the file name to: <name of your test Job>. DLL. config, so that you can read the web when the unit test is run. config content

 

Question 2:
XML files are used in the project to read some files or other external resources, which cannot be loaded in unit tests.

Solution:
1. If appdomian. currentdomain. basedirectory is used in the code, put the configuration file in the bin \ debug or bin \ release folder.
2. you can enable test setting, check enable deployment on the tab, and select the XML file to be copied or other external resources. Note, in this way, the default related path is changed to the test case in the testresult file.
3. You can write scripts in test setting to copy files.

 

Question 3:
Some files may be loaded incorrectly after the Web cache function is used.

Solution:
1. cache uses absolute paths instead of relative paths in unit test.

To sum up, unit test will not make any changes every time after the WEB Project is modified (the function is not changed). My approach is to write a prework method in unit test, and initialize this method in a class, and all the unit test classes inherit from this class.

 

If you have any questions about unit test, contact me :)

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.