One of the great things about ALT.NET is the variety of choices it affords.  However, this can also become an albatross around your neck when trying to choose a particular unit testing framework, mocking framework, IoC container, etc.  I mean, if you haven't tried most if not all of the choices, then you don't know what you're missing.  Of course you can read about the different options out there, but that's no substitute for trying them out for yourself.  Having said that, there's still a lot of utility in reading about them to exploit them to your advantage.  Thus, I recently moved out of my normal comfort-zone, (NUnit, Rhino.Mocks, Windsor Container) and tried some other technologies. 

What follows is a short description of my impression of a couple of Unit Testing frameworks that I've played with in the past couple of weeks.  Note that this is not intended to be an complete portrayal of each tool, but rather how I felt when attempting to use them.

NUnit

This is the old standby, but there's a 2.5 alpha that I hadn't tried.  I liked a lot of the changes that have gone into it, but found that too many things that I depend on for integrating with NUnit don't work with 2.5 yet.

XUnit

I like XUnit.  It's simple.  ALT.NET takes a bad rap for being hard to adopt, so one thing I try to emphasize is simplicity.  This is XUnit's strength.  If I were starting someone off in Unit Testing, I'd tell them to look at XUnit.  I have to admit that I do like the Constraint model in NUnit, however.  It just reads more naturally.  Also, pretty much everything works with NUnit, but not necessarily with XUnit (like TeamCity, currently).  So eventually, I went back to NUnit 2.4.8.  It worked fine with TestDriven.NET, however.

So the moral of the story is that software (including OSS) has momentum.  Once you get used to a certain way of development, it feels painful to switch, even if the other applications have some nice new features.

Conspicuously missing here is MbUnit, which I've tried in the past but again went back to NUnit eventually.  I'll have to try it out again soon.


 
February 20, 2008
@ 06:27 PM

As I've said before, my organization does an awful lot of SharePoint work.  Since button-pushing really isn't my thing, I've got only a few options when it comes to coding most SharePoint projects:

I've started to duplicate this blog on our internal MOSS server, and there's something that I've missed about dasBlog that's not available in WSS or MOSS blogs - Tag Clouds.  That sounds like a good place to get my feet wet in Web Part development.  I know that there are already several web parts available that provide tag clouds for MOSS, but of course, they're "not invented here".  No, seriously, this is purely for my own educational purposes, so even if I do provide a solution to the general public, there's certainly no assumption that it would be any better than what's already available.  This project will let me explore several interesting technologies:

Technorati Tags: ,,

 
Kick it! Digg it!  Categories: Agile | Automated Testing | IoC | MOSS | SharePoint

Well, not really.  From what I could tell the guys who were maintaining NCover and NCoverExplorer as OSS projects, have formed their own company, Gnoso.  Despite the title of this post, I’m not upset or anything.  I code for both fun and profit, why should I begrudge these guys their mortgage payment? 

Other OSS maintainers have also profited from their OSS efforts.  DotNetNukeCorporation & Interface21 (the folks behind Spring & Spring.NET) both offer support/consulting services for their respective OSS products.  The difference, however, is that both DotNetNuke and Spring.NET remain OSS, whereas NCover is now licensed software.  But it’s not like the price they’re charging is egregious – the Enterprise version is only $299, a drop in the bucket of any software development project.  And if that still causes you to choke, there’s the “Pro” version that’s only $149, not to mention that the older versions (< v 2.0) of NCover are still free.  So rock on Gnoso.  You’ll get my $299 sooner or later – as long as my boss or client lets me expense it!


 
October 3, 2007
@ 08:54 PM

I'm really excited about the new functionality in C# 3.0. With all the great extensions to the C# language, writing DSL-like code is going to be easier than ever. And writing DSL is the key to writing intentional code that your customer (whoever that may be) will more likely understand, appreciate, and use as the excuse to keep you on for the next project.

However, there are some issues with Orcas that are preventing me from going all out with it as my personal environment. Lack of proper ReSharper 3.0 support for Orcas is a big barrier for me. Sure, they say they have Orcas support, but only when working with non .NET 3.5 features. Place some C# 3.0 specific code in your class and ReSharper lights up Orcas like a Christmas Tree – errors detected everywhere, though you can compile just fine. ReSharper's parser just can't handle C# 3.0 yet. I'm sure it will eventually. So why can't I live without ReSharper? I'm sure I could, but it would be like the rest of the MS developer world going back to the pre-Intellisense days. There are simply too many modern conveniences built into ReSharper. I could turn off ReSharper syntax highlighting, but that disables about half of the useful features of ReSharper (in addition to simply syntax highlighting).

Besides weak ReSharper support in Orcas, another problem I have is that my ISP does not yet support .NET 3.5. Granted, not many do, but this limits me to posting source code. I can't write anything cool and run it on my site. If anyone knows of any FREE .NET 3.5 sites out there, let me know. I've already pushed the WAF (Wife Acceptance Factor) on my current ISP spending. Hmm… Note to self: maybe it's time to start accepting donations.

So there you have it – yes, I will continue to "play" with Orcas, but serious work, either professionally or in my own spare time, will remain in the .NET 2.0 world. Maybe I can keep "upgrade" in mind as I write my "donation site" code in .NET 2.0.


 
September 18, 2007
@ 08:52 PM

In my freshman year in college, my first Computer Science professor taught us to code bottom-up. The next seven semesters were spent un-learning bottom-up development. The next seventeen years out of college I spent doing Top-Down, Big-Requirements-Up-Front development. Then along comes Agile & TDD and I'm slowly working my way back to bottom-up again.

The devil's in the details is an old friend of mine's favorite saying, and it's the truth. So work the devil out early and go home early, right? Yes and no. You're going to have the devil putting things together in the end, then. Not that it's impossible, but still you have issues whether or not you start at the top or the bottom.

It took me a really long time to figure out the bottom-up thing with TDD. I kept trying to do TDD top-down, and was frustrated early on. After I did finally start doing bottom-up again every once in awhile I'd slip back into top-down mode. But having learned a little about agile by then, and still continuing, I think I've discovered something. You can do BOTH! You still start at a user story, the one that's going to deliver the best business value, but that's usually still pretty high level – especially the "high value" ones. So I'll start with a test that may not be an "end-to-end" test, but that still accomplishes a big chunk of work. Then I'll notice, hey, I have a need for another test that demonstrates a smaller piece of work, and so on, until I need get to the "bottom-up" level of detail. As I discover the need for a "smaller" test, I'll comment out the bigger test(s), and place a "TODO" comment at its head – ReSharper's TODO Explorer in 3.0 is great for that. Once all my TODO's are completed and all my tests pass, the user story is done and I can move onto the next – usually quicker than I expect. It's kind of like the feeling I get when I find unexpected cash in my pocket – time to celebrate!


 

Reducing duplication - that's a major goal of agile software development.  But how often are we duplicating actions throughout the days, weeks or months.  I'm not talking about something like eating, I like duplicating that for some reason, and on a regular basis, but drudgery I'd rather not repeat so often.  There are certain actions that I take on a regular basis that I'd like to automate.  Usually this comes as an epiphany usually followed by, "If I ever have to do that again, I'll (insert something nasty here)." 

How do we capture this kind of duplication?  Well, I have to start somewhere, so I'm starting with a text file.  No database.  No XML.  Just a description of something tedious that I must do followed by a bunch of "x"s.  Each time I do it I add another "x."  I should also assign a "difficulty to automate" threshold, and when I have enough tick-marks then I can justify the time it will take to automate that process.  That's the tough part, I think.  For example, mowing my grass would have to have a really high difficulty threshold, since I know nothing of robotics, though it might be a great chance to learn Microsoft Robotics Studio.  Or I could just invest $1,700 on RoboMow.  The Internet is a terrible thing sometimes - I wish I hadn't found that.

Anyway, maybe I could start with something easier, though I still seem to be on a robotics kick of some kind.  What really gets my goat is when I have to walk around my desk to my office door to unlock it for my wife or kids.  I have the sole printer.  My office is also our homeschool library.  I must do this same task twenty or more times every day.  If I leave the door open I'm permanently invaded.  I'm ready to automate door locking and unlocking - which could be a gentle introduction to robotics... somehow.  I sure don't want to pay $250 for a mag-lock, either.


 

I was surprised to find out today that you cannot tell whether or not a test has passed or failed in NUnit from within TearDown – and by design. The maintainers believe that such ability could be abused by people learning NUnit to perform tasks that are more appropriately performed by the framework itself. I understand where they're coming from, but I respectfully disagree.

I have a bunch of tests that I'm running through WatiN, and of course it's imperative to close IE after each test, otherwise you could quickly run out of resources. So I've had a TearDown routine that closes the browser for me. However, it sure is a pain to try to figure out what went wrong in a failed WatiN test without the aid of an open browser. So, I'd like to keep the browser open just for failed tests. Is that so wrong? And there's no easy way to do this in the current framework. So now I've had to remove the "TearDown" attribute from my WatiN teardown test fixtures and call "TearDown()" at the end of each test – not the ultimate in drudgery, but a nasty code-smell nonetheless.

I've put a request in to the NUnit-Users mailing list, as has been done before. We'll see if I get any mileage out of it this time.


 
September 1, 2007
@ 08:46 PM

Testing is about a lot of things.  One of the major things is confidence.  When you have good test coverage you can have the confidence to make changes (assuming that you run your tests after making your changes, which not everyone does).  Making changes to a production system is risky business and the importance of the staging environment is paramount.  This gives you the liberty to try out new technology, new functionality, and things that you would otherwise be afraid to attempt (or should be).  One should not let one's enthusiasm to impress overcome common sense and while performing rigorous testing is not glamorous it not only builds your own confidence, but other's confidence in you as well.  Shortcuts lead to not only grief but sometimes embarrassment as well.  Seeing green is such a good feeling.


 
July 3, 2007
@ 08:39 PM

CI Factory is another technology that I failed to put on my "to do" list. Nevertheless, I've been playing around with it this past week and from what I've seen so far, I really like it. I'm a little concerned that it could "kitchen sink" you to death, but on the whole, I think this is a great boon to someone trying to quickly bring up a continuous integration server. I still think it's better if you learn the basics of particularly CruiseControl.NET and NAnt yourself before bringing up a CI server. In fact, if you didn't at least have a basic understanding of these you wouldn't be able to troubleshoot any problems encountered along the way of bringing up CI Factory, nor would you be able to customize/extend it in any way. .NET Rocks! or more precisely dnr tv has what I would call the best screen cast so far explaining how to set up CI Factory. In about 1 hour Jay Flowers, Scott Hanselman, and Carl Franklin had the whole SubText open source project downloaded and incorporated into a brand-new CI Server, though I think Carl was kind of bored during the whole thing. Here are some of the "gotchas" (just actually things to be aware of) that I've discovered so far when installing CI Factory:

  • Don't try to develop on your buildserver, certain packages in CI factory get confused
  • Have Subversion installed (if you're using SVN) before you try to install CI Factory. Make sure you have it installed to C:\program files\subversion and that it's in your path
  • Have NCover installed before you try to install CI Factory
  • Go with the flow the first few times you attempt to install CI Factory. Don't try to customize it too much. Once you're familiar with how things work, then you can start to experiment.
  • I was getting errors trying to commit a large amount of information to Google Code during CI Factory setup

I'm a little concerned about using something like Google Code or CodePlex (with SVNBridge) with CI Factory on a large project. I know Google Code limits your storage to 100MB (too bad they can't have storage more like Gmail) and with literally no code in my CI solution I was up to an exported source of 311 MB in no time, though the Subversion repository itself was only about 15 MB. It would probably be OK for a small project without a lot of change, however. Where CI Factory will really shine for me is during customer engagements, with bringing in VM and installing a CI server, even for a pre-existing application such as was done with SubText in just an hour or so. Kudos to Jay Flowers, who must dream in NAnt.


 

I've done a couple more experiments with a simple "Hello World" version of a Presenter First style app.

With the first one, I've gotten rid of the manual mock objects (less code to maintain) and replaced it with dynamic mock objects from Rhino Mocks. I do believe that Oren Eini has thought of everything when he made Rhino: source code here

And with the second one, I've utilized not only the dynamic mocks, but also Windsor Container for the Windows Forms app, and an auto-mocking container developed by the folks at Eleutian for the TDD test. I must say, however, that it was a little tricky getting the Presenter object in the right state for auto-mocking + testing. At first I couldn't "auto-mock" the Presenter object before I'd obtained the View mock. The Presenter constructor was setting up the event subscription to the view, but I couldn't get to the Auto-Mocked view until the Presenter constructor was already called, which messed up my mock recording/playback sequence. Therefore, I had to add an "Initialize" method to the Presenter object. Again, it's a little more code in the short run, but if this were an extensive application, there would be a heck of a lot less monotonous configuration code for all the dependency injection stuff. I love the fact that the Windows Forms app has absolutely no idea what objects are being created for its use. That's all up to the configuration file: source code here


 

As mentioned in my last post, my first "Tech TODO" was to wrap my head around the "Presenter First" pattern. There are several videos (part 1, part 2, & part 3) from Ron Jacobs on the concept, and he spoke about it at Tech Ed 2007 in Orlando as well. The guys at Atomic Object also have several papers and what they consider a pretty simple example of Presenter First in action. Now, I'm not an agile newbie. I've written a couple apps that use the "Humble Dialog" approach to separating the GUI from the business objects in a testable way, but I could not for the life of me figure out how to "do" Presenter First from any of the available stuff online. Well, I did figure it out, but it took way-longer than I thought, based on how everyone was saying it was such an easy concept. Frankly, if you're not used to using events and delegates, it takes awhile to grok.

So in the spirit of sharing, I'm posting my first go-around with Presenter first. This is by far the simplest version of a Presenter First style app I've seen to date. Granted, it's useless for anything except to help you understand Presenter First, but then again, that's its purpose.

There are only about 50 lines of code, and honestly, Mort would have done this in about one line of code after double clicking the form's only button in the designer, but the thing is, he could never have automated tests for it! This is a case where the outcome (testable GUI) is worth a little extra work.

There following files are the interesting bits – first for the testable part:

  • IModel.cs & IView.cs – the interfaces for the model and view (duh)
  • MockModel.cs & MockView.cs – these are "manual mocks" (I wanted to keep it simple) for testing, and since I don't yet understand how to mock events and delegates in Rhino Mocks, yet.
  • Presenter.cs – the glue that ties things together, and more or less the main character in this exercise.
  • Test.cs – contains the Unit Tests for… testing

…and finally for the "live" windows form app:

  • Model.cs – the "real" model, and a very simple one, indeed (Prints "Hello world")
  • View.cs – a Windows Form, and the "real" view
  • Program.cs – the app runner, for any normal windows forms app

So there you go. You can get the source code here. Enjoy!


 

I'm getting a strange error this morning… or lack thereof. I know for a fact that a specific Web Service is failing, yet my test which calls it is passing. Looking closer, I can see that I'm not even connected to the network that the web service resides on when running this test, so there's no way it should be passing. I'm getting a false-negative (a test that fails when it really should pass is a false-positive). Why is this happening? My first suspicion is the Visual Studio test-integration tool for NUnit, in this case it's ReSharper. I have heard some negative comments about using ReSharper for your unit testing, and this may be the reason why. So let's try the test in the NUnit GUI. Whoa. It passes in the NUnit GUI. Why is that? I could test from the command-line, but I suspect that I'd get the same result.

Let's look at the test itself. Maybe there is a false assumption there. Interesting – I see a nice comment that says "TODO: Revise Test". That's not very illuminating. I'm pretty sure I didn't write this test personally, either. A quick check of the test doesn't reveal anything to me, either. It should fail given the lack of a proper network connection. Now, I should probably write a new "failing" test to test for the lack of a network connection, but I don't want to lose my train of thought, so let's try plain vanilla NUnit from the command line. Weird, it passes there, too. It must be the test. Um… I'm stupid. The test is expecting an exception, so of course it passes. Gahh…. That would explain the need to revise the test in my cryptic TODO. Maybe whoever was reading the test would be astute enough to figure out that there was an "ExpectedException". But as it turns out, it was a lack of "intentionality" in the name of the test. The test is named "CreateUser_Test". To me that implies that the test should successfully create a user. In fact, it fails to do so, intentionally (or just as a kludge). It would be more rightly called "CreateUser_Exception" or somesuch.


 
March 29, 2007
@ 05:09 PM

You may think I've been slacking, but really I've been scouting out new free technology!  WatiN is a very useful tool for performing web application testing. http://watin.sourceforge.net/.  A necessary companion to WatiN is a free tool from Microsoft called the IE Developer Toolbar.  Why have I never used this before?!?!  Thanks to Justin Miller for pointing me toward WatiN!

And of course this is still in the screen-cast series, so you won't get away without the obligatory WatiN Screen Cast (24+ MB)


 
March 6, 2007
@ 05:25 PM

Like I've said before, FxCop can be a pain in the patootey.  But it feels pretty nice when you run it and don't get any warnings.  This is a quick overview of how to use FxCop.

By the way, I apologize for the sound - something was up with my mic, apparently, but it should be OK if you turn up your volume.  I'll try to fix this before the next one.

 FxCop Screencast


 

This is a short one since I'm short on time.  I did want to get something out however, so here it is.  Enjoy the NCover screencast


 
March 4, 2007
@ 04:00 PM

NUnit is my unit testing tool of choice. I remember a few years ago when I was trying to figure out all of this automated unit testing stuff and the problems I had learning without someone to show me how. I hope that this screencast can make the introduction to automated unit testing a little simpler and make testing in particular more prevalent with those who view it.

NUnit Basics


 
February 26, 2007
@ 09:42 AM
Most likely it's just my noobishness with Selenium but I can't get it to work in some of the simplest scenarios sometimes.  So for now I'm embracing the philosophy of "The Humble Dialog" and discover ways to move functionality out of the UI and into the non-UI objects themselves. Model-View-Controller and all that.  In the future I'd like to build my own web-testing software - I'd make it free. 
 
The best Web-Testing framework I've ever used comes with Visual Studio 2005 Team Suite (or test), but for my "free" project that just won't work, because Team Suite and/or Test are definitely not free.