Daily Archives: October 14, 2007

Unit testing LINQ to SQL and Entity Framework

Even though I’m still a Unit Testing luddite, I’ve been looking around to see how people are getting LINQ to SQL and Entity Framework to work in their Unit Testing scenarios even though neither technology is really built to test against well.

First, I found this excellent post by Ian Cooper that explained not just unit testing, but what makes code apprpriate for unit testing. This was really enlightening for this newbie  (that is, moi) and gave me a much better understanding of why the TDD guys have been so frustrated wtih Entity Framework – although it is absolutely evolving in a way that will satisify them (more likely V2, then V1 though).

Ian also was able to find a way to do Unit Testing with LINQ to SQL.

Then I headed back over to Danny Simmons’ blog for this recent post on some key tweaks to make to the EDM (and codegen’ed classes (and now my brain knows enough to say “uh oh… codegen…that’s a problem for Unit Testing!”) work with Unit Testing.

Then I started playing with VS2008 to get a feel for how the tools enable me to do unit testing when have zero experience. I had give in and read through documentation (I know , how lame and lazy am I?) after I spent about 1/2 hour searching for a screencast or webcast on the topic. But I got some of the basics and figured out debugging, but still have some definite quandries! (Such as why do I get a failure when the expected value is 10 and the actual value is 11, but I get an inconclusive (rather than a pass) when the expected value is 10 and the actual value is 10?) I have a lot to learn! 🙂

I found Chris Buckett’s post on shoving EF into vS2008 Pro unit testing which helped a lot, mostly because he already understands unit testing and therefore understands what challenges he needs to solve when working with entity framework objects. The biggest issue about unit testing data access modules is that you don’t necessarily want to hit the database each time. to this point, Chris is trying to create a mock provider to emulate the database calls made by Entity Framework. Another issue is that you need classes that are instantiated without parameters. So while Danny tells us the simple trick for getting regular classes to fit into unit testing (in the above linked post), Chris is struggling with how to create an ObjectQuery return without instantiating an ObjectContext because the latter requires parameters. (Surely, I’ve gotten some bit of my interpretation wrong in a way that is making you TDD pro’s cringe, but I’m trying! :-))

I am happy to sit by the sidelines while he comes up with the model. (Subscribed)

Sad Soap Opera of the tiny town of my alma mater is on CNN.com’s home page today

I am a graduate of a college that I will love until the day I die, Well College. I went to Wells almost begrudgingly, with my heart set on studying film at a giant party school: Syracuse University. Being at a tiny 500 student school with no boys around seemed like hell for an 18 year old. During my first semester I begged my parents to let me transfer, but they made me promise to see the year out.

And I fell in love with Wells and spent my entire four years there, learning, learning who I was and not worrying about how I appear or sound to possible love-interests in my classes. It’s amazing to have all of that stripped away so that you can just keep your eye on the prize – getting a great education. I allude to this in my “Proud to be a Geekette” essay on OReillyNet’s Women in Tech series.

Wells is in a tiny little town in New York State on huge Cayuga Lake (one of the finger lakes) half way up the lake from Cornell (in Ithaca). Many former Wells students stayed in Aurora after graduating. Most continue to have strong ties in one way or another. Mine is through the incredible friendships that I have maintained with a number of women that I graduated with and are still the absolutely dearest friends in my life.

One former grad (from before my time) went on to create the American Doll company and in the 90’s sold it to Mattel for $700 million dollars. She decided to use a lot of her new-found fortune to help the college and to help the town. But it was soon apparent to many that her help came at a cost. She turned the town into a big doll house, which created a moral conundrum for so many and a rift through the residents of the town. I haven’t been back since my 5th reunion, but have been thinking that I’ll be there for the one coming in 2008. (my TWENTY-5th! Egad!). I wonder if I’ll mourn the old Fargo, where I spent probably more evenings over those 4 years than I would like to admit. Oh, the memories! 😉

While my suspicion is that there is a Wells alum working at CNN, it must be a slow news day because this is the headline story on CNN.com this morning. In reality, the article comes from the AP Newswire and was written by Helen O’Neill.