background preloader

TDD

Facebook Twitter

James Carr » Blog Archive » TDD Anti-Patterns. Recently I began to write a paper on TDD Anti-Patterns, and decided to first quickly jot down some of the most common ones that others or myself have encountered “in the wild.” I then posted what I had on the testdrivendevelopment on yahoogroups mailing list, and got an excellent bit of feedback! As a side note, keep in mind this is merely a catalog at the moment, hopefully to be expanded in full down the road. TDD Anti-Pattern Catalogue The Liar An entire unit test that passes all of the test cases it has and appears valid, but upon closer inspection it is discovered that it doesn’t really test the intended target at all. Excessive Setup A test that requires a lot of work setting up in order to even begin testing. The Giant A unit test that, although it is validly testing the object under test, can span thousands of lines and contain many many test cases.

The Mockery Sometimes mocking can be good, and handy. The Inspector Generous Leftovers [4] The Local Hero [1] The Nitpicker [1] The Dodger [1] .Net Mocking Frameworks - Capability Comparison | PHP vs .Net. I have a couple years of experience of TDD under my belt, but it's only recently that I've felt like I am a relatively decent practitioner of it.

I attribute this to forcing myself to take the plunge into mocking, and the knowledge of patterns and loosely-coupled design that I've gained from it. You see, I work on a pretty large and complex ASP.Net webforms product, and tests were introduced late into the development cycle of the initial release. We favored integration testing with real data sources over actual unit tests. While I did write some tests, I knew that our product was not very testable by design. Recently we put together a public facing API for programming against the product, that we were able to build from scratch. Several weeks down the road, it was obvious that Rhino just isn't right for our environment. This led me on a frustrating research mission to find the differences between frameworks without actually trying them all. .Net Mocking Framework Comparison Other Notes.

REST Anti-Patterns. When people start trying out REST, they usually start looking around for examples – and not only find a lot of examples that claim to be “RESTful”, or are labeled as a “REST API”, but also dig up a lot of discussions about why a specific service that claims to do REST actually fails to do so. Why does this happen? HTTP is nothing new, but it has been applied in a wide variety of ways. Some of them were in line with the ideas the Web’s designers had in mind, but many were not. Applying REST principles to your HTTP applications, whether you build them for human consumption, for use by another program, or both, means that you do the exact opposite: You try to use the Web “correctly”, or if you object to the idea that one is “right” and one is “wrong”: in a RESTful way.

For many, this is indeed a very new approach. As with any new approach, it helps to be aware of some common patterns. Let’s start with a quick list of anti-patterns I’ve managed to come up with: Mock library for .NET 3.5 with deep C# 3.0 integration. Best and Worst Practices for Mock Objects - Jeremy D. Miller -- Mock objects are like any other tool. Used one way they’re a huge time saver. In other cases they can easily create more work and degrade the quality of the testing code. In this post I’ll try to present some best and worst practices for utilizing mock objects. Sadly, every “bad” practice described is something I’ve either done or seen done.

This is the third in a planned series of five posts on mock objects: Introduction to Mocks and StubsWhen and Why to use Mocks and Stubs Best Practices for Mocks (this post)Constraints and other Mocking Tricks Attaching Mocks and Stubs with StructureMap (by request) Mocking Interfaces and Classes outside Your Code Be careful about mocking or stubbing any interface that is outside your own codebase. The best example from my memory was a security subsystem that retrieved security authorization and user information from Active Directory.

Public interface IUserInformationStore UserInformation FindUser(string userName); Don’t mock fine grained interfaces.