Click here to Skip to main content
15,942,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, may I know is there any tool/library/generator that i can refer to in order to generate general unit test method?
For example, i have a method that goes to DB to retrieve data, i need to ensure that method does not return null. For traditionally way, i need to code a unit test to check for that method(e.g. Assert.IsNullOrEmpty()). I hate to admit it here but due to my team's laziness that they are unwilling to write unit test codes for the development they have done(i am not their superior sigh), i am currently looking for any extention that i can use to help them to save some work load(like plug and play for Assert.IsNullOrEmpty()). For example, i can just press that dot(.) then an extension will pop out for me to choose which checking that i want to have w/o having to code the unit test coding.
My team is using MOQ framework now for their unit testing.

Any suggestion would be very appreciated. Thank you.

What I have tried:

1. Search online for suggestion but to no avail.
Posted
Updated 2-Apr-18 22:32pm

1 solution

First off if it needs a database it isn't a unit test; unit tests are to check your logic, not what data you have in a database or connectivity. Those kind of tests are integration tests and will be done elsewhere, probably as a separate process. Unit tests should be able to run when the project is built and shouldn't rely on external resources.

Secondly unit tests are supposed to be independent of the code, you can write the unit test before you've written the code, they should be driven by business requirements. If you are using an auto-generator then you are writing a test from the code. I appreciate that's how most unit tests are done in the real world though.

Thirdly any test that can be automatically generated is going to have little value, it takes careful analysis and thinking to construct proper tests.

The best you can probably do is write your own tests which will build up a library of functions that can be copy and pasted and the "guts" changed to match the code being tested. Ultimately though this is a people-problem, if your company doesn't have the right culture\attitude then the solution is not a Visual Studio add-in.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900