background preloader


Facebook Twitter


Unittesting. Mockobjects. Userstories. Guide: Writing Testable Code. To keep our code at Google in the best possible shape we provided our software engineers with these constant reminders.

Guide: Writing Testable Code

Now, we are happy to share them with the world. Many thanks to these folks for inspiration and hours of hard work getting this guide done: Also thanks to Blaine R Southam who has turned it into a pdf book. Flaw #1: Constructor does Real Work Warning Signs new keyword in a constructor or at field declaration Static method calls in a constructor or at field declaration Anything more than field assignment in constructors Object not fully initialized after the constructor finishes (watch out for initialize methods) Control flow (conditional or looping logic) in a constructor Code does complex object graph construction inside a constructor rather than using a factory or builder Adding or using an initialization block.

NHibernate 2.0, SQLite, and In-Memory Databases. For anyone who is having issues with in-memory SQLite databases and NHibernate 2, check this post out! I have been playing around recently with a bit of code that I needed a database to hit against to test it. The code was using NHibernate to directly access the database, so I couldn’t just mock a layer and fake it, I really needed a relational database to access. So, I began to look around the net, and I found several posts (including this one by Oren Eini) where people have referenced using an in memory SQLite database to test against. Most of them were a bit older, and most of them were using NHibernate 1.2, but they were a good enough starting point where I could get all of my code setup. The problem was that once I got all of it setup, I was still getting exceptions from SQLite stating that it couldn’t find the table when I went to query it.

Before I go into how I finally resolved this error, let me first go through my setup. Same deal as you saw in Oren’s post. Be Sociable, Share! Unhandled Exceptions » Blog Archive » UnitTest Utility Library U. A number of readers of this blog have let me know that they have adopted the UnitTestBase and DatabaseUnitTestBase classes that I originally demonstrated from the Summer of NHibernate screencast series as a simple means of facilitating their writing of unit tests.

Unhandled Exceptions » Blog Archive » UnitTest Utility Library U

This is great news as I’m glad others have been finding value in the library and I had of course encouraged anyone interested to try it out and adopt it if it met their needs. These abstract base classes (from which consumers would derive their concrete test fixture classes) provide several convenience facilities that make it slightly easier for a developer to write tests that leverage the RhinoMocks mock objects framework as well as significantly easier to write tests that leverage the NDbUnit database-state-management framework when writing database-interaction unit tests (ok, technically these are integration tests, but you get the point).

Some of these conveniences are… The Challenge. TDD and Hard to Test Areas, Part1 - Ian Cooper [MVP] I wanted to talk about the issues that people get when they begin working with TDD, the same issues that tend to make them abandon TDD after an initial experiment.

TDD and Hard to Test Areas, Part1 - Ian Cooper [MVP]

Those are the ‘hard-to-test’ areas, the things production code needs to do, that those presentations and introductory books just don’t seem to explain well. In this post we will start with a quick review of TDD, and then get into why people fail when they start trying to use it. Next time around we will look more closely at solutions. Review Clean Code Now TDD is an approach to development in which we write our tests, before writing production code.

Tests help us improve quality: Tests give us prompt feedback. Automated tests lower the cost of performing these tests. The Steps The steps in TDD are often described as Red-Green-Refactor. - Unit Testing for .NET - Release: 1.0.2. TDD Tips: Test Naming Conventions & Guidelines. The idea behind test driven development is that you are writing the test first. Since all code must reside in a method, the very first step before you can write any code, is to name the test. If you're new to TDD, you'll find this to be a very difficult thing to do. Don't let this discourage you, I'd go so far to say that out of all the tasks a developer must accomplish, finding names for things is perhaps the most difficult. W.H. Auden's statement show's that this "meta" thing transcends development: Proper names are poetry in the raw.

TDD and Dependency Injection with ASP.NET MVC. One of the guiding principles in the design of the new ASP.NET MVC Framework is enabling TDD (Test Driven Development) when building a web application.

TDD and Dependency Injection with ASP.NET MVC

If you want to follow along, this post makes use of ASP.NET MVC CodePlex Preview 4 which you’ll need to install from CodePlex. I’ll try and keep this post up to date with the latest releases, but it may take me time to get around to it. This post will provide a somewhat detailed walk-through of building a web application in a Test Driven manner while also demonstrating one way to integrate a Dependency Injection (DI) Framework into an ASP.NET MVC app.

At the very end, you can download the code. I chose StructureMap 2.0 for the DI framework simply because I’m familiar with it and it requires very little code and configuration. Start Me Up! Once the CTP is released and you have it installed, open Visual Studio 2008 and select the File | New Projectmenu item. New Project Select Unit Test Project Project Tree Ok, we better stop here. Index at