Bat Monobile 12 May 2007


These last days, I've been working on a little framework based both on Boo and NUnit called Bat. Bat stands for Boo Assembly Tester, and is attended to simplify the creation of unit tests for everything Cecil based.

For instance, let say I want to test the way Cecil emits assemblies, with a very simple Hello World assembly, here is the declaration of the test:
[Test]
public void CreateHelloWorld ()
{
	RunWriteAssemblyTestCase ("HelloWorld");
}
And here is the actual test:
"""
Hello, world!
"""

worker = Main.CilWorker

worker.Emit(OpCodes.Ldstr, "Hello, world!")
worker.Emit(OpCodes.Call, ImportConsoleWriteLine())
worker.Emit(OpCodes.Ret)
The method RunWriteAssemblyTestCase will compile the Boo script, run it, and thus create a new assembly, run the assembly, and ensure that the output match the documentation of the Boo script.

The framework provides helper to test the ability to read assemblies, or to round trip them, and ensure that they still work as expected. The good thing is that it should be pretty easy to create it's own helpers on top of that to write tests for assembly linking, merging, or for whatever tool that manipulates Cecil assemblies.

If you're interested in writing unit tests for Cecil, you can checkout at the bat project and the updated Mono.Cecil.Tests project. People working with Cecil, don't hesitate to submit new unit tests now that it's both fun and easy!

This work is eavily influenced by what my friend Rodrigo and I have done on our different projects that always end up manipulating assemblies :) Thank you Rodrigo!