A Poll aboutmy TechEd demos: Console App or Unit Tests?

Many of the demos I do with Entity Framework do not involve the UI. In order to run them however, I need to start with some type of exe, so I just build a console app whose main method calls the different methods to demonstrate functionality.

Someone suggested that rather than use the console app, I use unit tests to fire off the methods. It's a fun exercise for me, but I'm worried that the extra layer (the unit tests) might throw off anyone in the audience who is not familiar with unit testing. THey will be trying to understand how the tests are constructed rather than focusing on the EF code I am trying to demonstrate.

With a console app, there is a simple line to call a method - e.g. SearchableArguments whereas a unit test has to instantiate the calling class, then instantiate a result, call the result and validate the result. And the act of running/debugging the tests also is visually distracting since it has a separate interface and it's little green (you bet they'll be green!) lights.

What do you think? Should I use the lame but cleaner, less distracting way of running my demos (console app) or do the "right way" which has the potential of distracting a subset of the attendees from the core lessons?

Part of the equation is how many attendees will be unfamiliar with unit testing vs. how many u.t. pros will be annoyed by the console app?

Personally, I lean towards the cleaner way - console app. But I thought I would try to get a consensus. If you do reply, do indicate if you will actually be in these sessions ("EF Tips and Tricks" and "Surprise! It's the Entity Framework Gotchas")

Thanks!

#1 bill burrows on 4.26.2009 at 11:54 AM

Hi Julie,I agree with your "leaning". Examples need to focus on the topic of the example with as little distraction as possible (IMHO). Too often I have been looking at sample code where the content being shown is obfuscated by other code that just adds to confusion.bill

#2 Michael L Perry on 4.26.2009 at 1:44 PM

I'm afraid I won't be in attendance, but I prefer the console app.People debate over the "right way" to unit test. There's TDD, BDD, context/specification, etc. Most would agree, however, that unit tests that depend upon a database are not unit tests at all. I'd suggest you just stay out of that little religious war and don't risk promoting unit tests against the database as the "right way".

#3 Julie on 4.26.2009 at 3:44 PM

@Michael-I know these aren't "real" unit tests. I'm hitting the db and I'm not really "testing functionality" as much as avoiding the issue of having to use a UI just to debug some code.The last thing I need is to get in the middel of yet another war. I've had enough of that with EF. :-)Thanks Bill & Michael for your feedback. I think this was already one of those "if you have to ask..." scenarios.julie

#4 Ian Griffiths on 4.26.2009 at 4:37 PM

I think there's another reason beyond the religious "tests that hit the DB aren't unit tests" debate:Unit tests should test *your* code, rather than the framework. So if you were going to do this The Right Way, you should write a test that verifies that the code you want to demo does what it's supposed to do. (Possibly by mocking the EF...that sounds like hard work. Definitely a bit much for a demo, I think.)It sounds like what you're proposing is, in effect, a test that verifies that the EF does what it's supposed to. So it's not like this would be a realistic illustration of what you'd put in a real unit test. So I'd stick with the console app.

#5 Don DeCosta on 4.26.2009 at 9:49 PM

Have you watched any of the Summer of Nhibernate videos? (http://www.summerofnhibernate.com/)They aren't just training videos for Nhibernate, they are also examples of unit testing.I wish I had the skills to do a comparable set of videos using EF and native Visual Studio Unit Tests.I won't be at TechEd but I was at Vegas DevConnections in your preconference day-long EF session and I did enjoy your Console App demos but the Summer of Nhibernate videos do a good job of teaching ORM and Unit Testing so it can be done without overwhelming.But maybe it takes 14 hours of online video to pull off.So, for a 1 hour session you're probably better off sticking with console app.

#6 Julie on 4.26.2009 at 10:09 PM

Well, I'm 150% confident with my original m.o. Thanks for all of the feedback.

#7 Rod Paddock on 4.27.2009 at 8:11 AM

I like the idea of you using your unit test runner. You don't even need to mention what it is. It's just a tool to run small fragments of code. Just my 2 cents.

#8 Sam M on 5.14.2009 at 4:45 PM

You can have your cake and eat it too.With .NET, both exe's and dll's are "assemblies".There's no reason your exe assembly can't be used for unit testing.You have it call whichever methods you want in your static void Main(), which is in a class named Program, which is NOT tagged with a [TestFixture] attribute.Main() might do something like this:DataTests tests = new DataTests();tests.Setup();tests.CreateTest();tests.UpdateTest();tests.TearDown();So Main() will run whichever tests you want, and that's what your program will do when you run it.But there's no reason you can't throw the exe at NUnit, which will ignore the Program class and the Main() method completely.Nunit would simply find all of the classes tagged with [TestFixture], and would run their tests.Best of both worlds.This is what we do where we work.

Leave a Comment