Posts

Showing posts with the label MSTest

ToMethodObject Refactoring

Image
I love refactoring code. To refactor code safely you need automated tests. Some code, especially code not written using Test Driven Development(TDD), make it difficult to write tests for the part of the code you are looking to change. Usually what you face are a class that has many dependencies, so in your test setup, you have to create all these dependencies to inject into the constructor even though many or perhaps all of these dependencies don't even have anything to do with the part of the code you are looking to change. Or the method that you want to write a change for is private and the calling public method has a bunch of dependencies which again many will not have anything to do with the part of the code you are looking to change. You are thinking: "If only this code was in a public method it would be so much easier to test". But you may have heard somewhere that changing the code just to make it easier to test is bad.  This is a terrible line of thought that has ...

How to include a file in Visual Studio MSTest

Once in a while I add a xml file to be processed as part of an integration test in a MSTest project in Visual Studio but the file is missing when the test is run.  Here are the steps to get the file to show up when the test is run: Add file to MSTest project and set it to copy always. Go to Test -> Edit test settings -> Local(local.testsettings) Select Deployment Check “Enable deployment” Add DeploymentItem(“nameoffile”) attribute to test RESTART Visual Studio! Remember to do step 6 because it will only begin working after Visual Studio is restarted.

.NET generics with private accessors not compatible with MSTest

Was playing around with generics and suddenly my unit test project failed with this error: “Signature of the body and declaration in a method implementation do not match.” After some research I found a post here http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/b54e6634-1542-4bd8-a227-029bfb679dec that explained my problem was using a private on a generic class, and was a known bug that will not be fixed in VS 2010 as explained here https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=415357 .  Changed the private to public and was able to carry on.