Ayende @ Rahien

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

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 10 | Comments: 37

filter by tags archive

Create a test DSL to test the DSL

time to read 1 min | 87 words

Yesterday I asked how we can efficiently test this piece of code:

specification @vacations:
	requires @scheduling_work
	requires @external_connections

Trying to test that with C# code resulted in 1500% disparity in number of lines of code. Obviously a different approach was needed. Since I am in a DSL state of mind, I wrote a test DSL for this:

script "quotes/simple.boo"

with @vacations:
	should_require @scheduling_work
	should_require @external_connections	

with @scheduling_work:
	should_have_no_requirements

I like this.

You can take a look at the code here.


Comments

James Gregory

Nice, but how are you going to test that the testing DSL works? ;)

Dan
Dan

Are you going to test this new DSL with itself?

Ayende Rahien

Quis custodiet ipsos custodes?

Benny Thomas

Its kind of nice. You have to write a TestDSL engine to test your dependencies on your DSL script.

What happens if you shuffle the should_require statements?

Ayende Rahien

Nothing much, there isn't an order dependency in the implementation that I wrote for them

Aaron Jensen

That's a lot more than a 1500% disparity now (yes I know it's just framework code and its not repeated, I'm just being pedantic). I think writing another full on boo dsl for testing something so trivial is a bit extreme. Why not just a base test class? Or some extension methods?

"quotes/simple.boo".With("vacations").ShouldRequire("scheduling_work")

"quotes/simple.boo".With("vacations").ShouldRequire("external_connections")

"quotes/simple.boo".With("scheduling_work").ShouldHaveNoRequirements()

Totally breaks AAA, but that's easily fixable.

Rob
Rob

Creating testing DSL's is something I just started doing and it has been awesome. I found that there are certain patterns that one tests repeatedly, so this can help.

Max
Max

You aren't testing the code, you're writing the same program twice :-)

Is this really useful?

Ayende Rahien

Max,

Try this, then:

Script:

specification @vacations:

requires @scheduling_work

requires @external_connections if UserCount > 50

Tests:

with @vacations, Users(51):

should_require @scheduling_work

should_require @external_connections

with @vacations, Users(49):

should_require @scheduling_work

should_not_require @external_connections
Ayende Rahien

Aaron,

That is because you consider only the code that you have here. Consider the case of a useful DSL where you have plenty of scripts that you want to test.

Since the cost of writing a DSL is very low, I see this is as a huge benefit.

vedic

yes. that also. 1500% is exactly... well... more or less more than 90% less time.

i like this too.

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. Production postmortem: The case of the memory eater and high load - about one day from now
  2. Production postmortem: The case of the lying configuration file - 2 days from now
  3. Production postmortem: The industry at large - 3 days from now
  4. The insidious cost of allocations - 4 days from now
  5. Find the bug: The concurrent memory buster - 5 days from now

And 4 more posts are pending...

There are posts all the way to Sep 10, 2015

RECENT SERIES

  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    14 Aug 2015 - The case of the man in the middle
  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

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats