Visual Studio 2010 generated a bunch of unit tests for me which seems to be handy, but I question whether they are actual unit tests. For example, it generated a test it called SaveTest which executes the following code:
User user = new User(); //I have to create a user
user.Save(); //This saves the user to the database.
//Assertions here....
The problem I have above is that from what I have read, unit tests are supposed to test things in Isolation, so by testing Saving to the database, this is not a unit test or am I wrong and does MsTest get it wrong? As a side note, User is generated from by dbml and Save calles SubmitChanges on my DataContext.
The auto-generated tests are only unit tests if you’ve already done the necessary work to isolate dependencies so that the calls with side effects can be routed to the appropriate mocked or stubbed dependencies for sensing the desired effects. The tools won’t do the work of architecting your code to support unit testing; all they can do is create calls to the various public access points. You’ll also still have to do the work of arranging your dependency states for each test and asserting the conditions you wish to check.