简体   繁体   中英

How to run unit tests when running the application in visual studio

We're trying to run automated tests of our functions using a unit test program in visual studio but we need to connect to the database in order to run them successfully. The program only connects to the database when the whole solution is run, so is there a way to run the unit tests when you run the solution?

The main point of unit testing is separating everything else from the class under test. For example, when you testing your UserService to see if CreateNewUser() function is successful or not, you need to remove all dependencies by using test doubles as mock, stub, fake etc.

After creating a double for the dependencies(database connection), you can call your function to see it is working if every dependency works correctly . So you will see if your unit of code is doing its job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM