Thoughts on IronRuby and .Net Testing

Today I wrote some IronRuby tests targetting C# code (using both MSpec and the bundled Test::Unit). Things went out absolutely well.

While I won’t share the code in question yet, here’s a working example provided by John Lam on his blog a while back. This morning I decided I would start running it myself, to see how it goes. You’ll have to git clone MSpec under the gems folder to get it working.


$LOAD_PATH << File.dirname(__FILE__) + "/gems/mspec/lib" 
require 'mspec'

require 'mscorlib'
include System::Collections

describe ".Net Stack" do
  it "creates an instance with zero elements" do
    Stack.new.count.should == 0
  end

  it "contains one element after push" do
    s = Stack.new
    s.push "bob" 
    s.count.should == 1
  end

  it "let us peek the element pushed" do
    s = Stack.new
    s.push "bob" 
    s.peek.should == "bb" 
    s.count.should == 1
  end
end

Notice how it mixes IronRuby code with the Stack CLR class.

My belief is that IronRuby and IronPython are going to deeply change the way people work with .Net.

I have the same feeling I had in 2001, when I started using C#. That feeling was: C++ is going to be used at the driver/infrastructure level, and most application code will move away to C#. Today it’s very clear to me that the same thing is going to happen: IronRuby or IronPython will be used for most of the daily code, while C# will gradually serve as an infrastructure.

As well my feeling is that given the dynamic nature of Ruby, a lot of the features of MbUnit or NUnit (such as combinatorial tests or row tests, see here for instance) are going to be easy to reproduce by yourself, as you need it.

Here’s an imaginary example so you get the idea:


$LOAD_PATH << File.dirname(__FILE__) + "/gems/mspec/lib" 
require 'mspec'

describe "SupaComputa" do

  (1..400).each do |value|
    it "computes 2^#{value} without blowing" do
      SupaComputa.new.pow(2,value)
    end
  end

end

It doesn’t remove the need for testing frameworks like MbUnit of course, but this is definitely going to change the way we test.

If you made it to the end of this post, be sure to check out John Lam’s talk at RubyConf 2008 (should be embedded below as well).

The comments system is brand new - don't be afraid to comment!