Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 18 | Comments: 82

filter by tags archive

Unit testing a DSL

time to read 1 min | 136 words

There is something that really bothers me when I want to test this code:

specification @vacations:
	requires @scheduling_work
	requires @external_connections

And I come up with this test:

public class QuoteGenerationTest
	private DslFactory dslFactory;

	public void SetUp()
		dslFactory = new DslFactory();
		dslFactory.Register<QuoteGeneratorRule>(new QuoteGenerationDslEngine());

	public void CanCompile()
		QuoteGeneratorRule rule = dslFactory.Create<QuoteGeneratorRule>(
			new RequirementsInformation(200, "vacations"));

	public void WhenUsingVacations_SchedulingWork_And_ExternalConnections_AreRequired()
		QuoteGeneratorRule rule = dslFactory.Create<QuoteGeneratorRule>(
			new RequirementsInformation(200, "vacations"));

		SystemModule module = rule.Modules[0];
		Assert.AreEqual("vacations", module.Name);
		Assert.AreEqual(2, module.Requirements.Count);
		Assert.AreEqual("scheduling_work", module.Requirements[0]);
		Assert.AreEqual("external_connections", module.Requirements[1]);

	public void WhenUsingSchedulingWork_HasNoRequirements()
		QuoteGeneratorRule rule = dslFactory.Create<QuoteGeneratorRule>(
			new RequirementsInformation(200, "scheduling_work"));

		Assert.AreEqual(0, rule.Modules.Count);

I mean, I heard about disparity in number of lines, but I think that this is beyond ridiculous.


Jimmy Bogard

Looks like you need a DSL unit testing DSL. If that makes any sense. But I wouldn't expect to unit test C++ in assembly.

Comment preview

Comments have been closed on this topic.


  1. The insidious cost of allocations - 16 hours from now
  2. Buffer allocation strategies: A possible solution - 4 days from now
  3. Buffer allocation strategies: Explaining the solution - 5 days from now
  4. Buffer allocation strategies: Bad usage patterns - 6 days from now
  5. The useless text book algorithms - 7 days from now

And 1 more posts are pending...

There are posts all the way to Sep 11, 2015


  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    03 Sep 2015 - The industry at large
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats