Chris Pietschmann

husband, father, hacker, entrepreneur, futurist, innovator, autodidact

NAVIGATION - SEARCH

TDD: Testable is most important

Test Driven Development (TDD) is great and it really helps you build better, higher quality systems. Unit Tests FTW! However, when TDD meets the real world, there is a clash and many times developers just don't write unit tests. This is bad, but it can be better if the right steps are taken. Writing code that is testable is the key; whether you write the unit tests now or later. Testability FTW! Testability is when you write code using the same best practices (short methods, use interfaces, clea... [More]

Mocking HttpRequestBase.ServerVariables using Moq

Mocking is a very handy tool for unit testing code, especially when it comes to mocking the HttpContext for web application code. However, it’s not as straight forward as you might think to mock the HttpRequestBase.ServerVariables, however once you know what to do it really is pretty simple. Here’s a code example (using moq) that shows how to create a mock HttpContextBase that contains a mock HttpRequestBase with a mock ServerVariables property: public HttpContextBase CreateMockHttpContext() ... [More]

Unit Testing with SqlException in .NET: Only with help from Reflection

If you are writing you code to be able to easily unit test each method, and you would like to unit test situations where a SqlException exception is thrown, then you’ll definitely run into the issue of the SqlException objects constructor being marked “internal.” Members marked “internal” can be a nightmare for unit testing, and they are found all over the place in the .NET Framework. Basically you can’t call “internal” methods, constructors, fields, etc from you own code because it doesn’t resi... [More]