Failure is inevitable


A Simple Trick to View Data in SQL Server While Your Specs Are Running

It’s ridiculously easy to do integration testing against Entity Framework and a real database when you are using SpecsFor.   I use SpecsFor to do all my integration testing.   But it occurred to me that I’ve never publicly documented one of the common tricks I use: viewing data in the test database while the specs are running.

One of the tricks I show in my course is how to leverage behaviors to make it easy to spin up and tear down a transaction around your SpecsFor specs.  But, if you set a break point and debug your spec, then try to query the test database to see what’s actually in your database while the spec is running, you’ll probably encounter a query that never completes, at least not until you stop the debugger.   That’s because there’s an active transaction! 

To get around it, just run this simple command in your SQL query window: SET TRAN ISOLATION LEVEL READ UNCOMMITTED

Now you can query your SQL database when you hit a breakpoint to see what’s really in there!

About Matt Honeycutt...

Matt Honeycutt is a software architect specializing in ASP.NET web applications, particularly ASP.NET MVC. He has over a decade of experience in building (and testing!) web applications. He’s an avid practitioner of Test-Driven Development, creating both the SpecsFor and SpecsFor.Mvc frameworks.

He's also an author for Pluralsight, where he publishes courses on everything from web applications to testing!

blog comments powered by Disqus