NUnit/Watir/Ruby Test Integration
Travis Illig took my NUnit/Watir integration POC and ran screaming down the street with it and has released his code on CodeProject. There are also some other integration projects in a similar vein going on that I'll post about later.
Travis' solution is clever in it's use of attributes. It does everything automatically that I did manually with resource extraction. The easiest way to grok it is to look at a sample NUnit test you'd write:
using System;
using NUnit.Framework;
using RTE = Foo.RubyTestExecutor;
namespace Foo.Test
{
[TestFixture]
public class RubyTestExecutor
{
[Test(Description="Verifies you may run standard NUnit-only tests.")]
public void NUnitOnly_NoRubyAttrib()
{
Assert.IsTrue(true, "This NUnit-only test should always pass.");
}
[RubyTest("Foo.Test.Scripts.RubyTest.rb", "test_Valid")]
[Test(Description="Verifies a valid Ruby test will execute.")]
public void RubyTest_Valid()
{
RTE.ExecuteTest();
}
[WatirTest("Foo.Test.Scripts.WatirTest.rb", "test_Valid")]
[Test(Description="Verifies a valid WATIR test will execute.")]
public void WatirTest_Valid()
{
RTE.ExecuteTest();
}
[RubySupportFile("Foo.Test.Scripts.supportfile.txt",
"supportfile.txt")]
[RubySupportFile("Foo.Test.Scripts.SubFolder1.supportfile1.txt",
@"SubFolder1\supportfile1.txt")]
[RubyTest("Foo.Test.Scripts.RubyTest.rb",
"test_RubySupportFile")]
[Test(Description="Verifies Ruby support files can be extracted.")]
public void RubySupportFile_Valid()
{
RTE.ExecuteTest();
}
}
}
It's the ExecuteTest() of course that does all the heavy lifting by walking the call stack looking for Attributes and acting on them. Check out his article and get involved.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
We use SgmlReader to parse the HTML (giving us a valid XML doc), and then use XPath expressions to validate it. All of this is done within the NUnit testing framework.
This is a really nice way to go, IMO, b/c you don't need to learn a new programming language (like Ruby), and you can still use a test-driven development approach.
Comments are closed.
To quote your original post, "We talked about adding [WatirTest] attributes or extending a new WatirTestCase and even a whole new series of Assertions, but we didn't see any reason to be tricky, other than to be tricky. We opted for simple simple simple."
And it was simple. And effective. And easy to integrate in any other type of class, like non-NUnit classes. I actually wrote a service to monitor website availability (and page me if there's trouble) using it.
While I admire Travis' code for its cleverness, I still prefer the Hanselman method.