Yesterday I posted a way to do negative DB unit testing. Essentially you wrapped your negative case in a TRY/CATCH block in SQL. There is another way to do this that is a little bit more work but, in my opinion, a little bit more correct. In the example I gave, there was a call to an API to create a user record that had no parameters. The test was created in a database test class called 'apiTest_createUser.cs'. Create a new test in this class and call it 'noDataSpecified'. Insert your code that you expect to error. In my case, I will use this:
EXEC Api_CreateUserRecords
Save your test. Goto the solutions explorer and right-mouse button on the test class you just saved (apiTest_CreateUser). You will see the option to 'view code'. Select that and you will see the code the designer is managing for you. Find the method that corresponds to the name of the test you created (noDataSpecified). The method will be prefixed with '[TestMethod()]'. Add another line below that which looks something like this:
[
That's it. I am not sure which approach is the "right" way to do this type of DB testing, but both seem to work. My preference is to use the attribute on the test method, but this seems to take more time to do and if you have many of tests to create, time is an important factor.