views:

175

answers:

6

We want to design a simple domain specific language for writing test scripts to automatically test a XML-based interface of one of our applications. A sample test would be:

  • Get an input XML file from network shared folder or subversion repository
  • Import the XML file using the interface
  • Check if the import result message was successfull
  • Export the XML corresponding to the object that was just imported using the interface and check if it correct.

If the domain specific language can be declarative and its statements look as close as my sentences in the sample above as possible, it will be awesome because people won't necessarily have to be programmers to understand/write/maintain the tests. Something like:

newObject = GET FILE "http://svn/repos/template1.xml"
reponseMessage = IMPORT newObject
newObjectID = GET PROPERTY '/object/id/' FROM responseMessage
(..)

But then I'm not sure how to implement a simple parser for that languange in Java. Back in school, 10 years ago, I coded a language parser using Lex and Yacc for the C language. Maybe an approach would be to use some equivalent for Java?

Or, I could give up the idea of having a declarative language and choose an XML-based language instead, which would possibly be easier to create a parser for? What approach would you recommend?

+5  A: 

You could try JavaCC or Antlr for creating a parser for your domain specific language. If the editors of that file are not programmers, I would prefer this approach over XML.

Péter Török
+2  A: 

Look at Antlr library. You'll have to use EBNF grammatic to describe your language and then use Antlr to make java classes from your grammatic.

Roman
+3  A: 

ANTLR should suffice

ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages. ANTLR provides excellent support for tree construction, tree walking, translation, error recovery, and error reporting.

Bozho
+1  A: 

Or, I could give up the idea of having a declarative language and choose an XML-based language instead, which would possibly be easier to create a parser for? What approach would you recommend?

  1. This could be easily done using XML to describe your test scenarios.

    < GETFILE object="newObject" file="http://svn/repos/template1.xml"/ >

  2. Since your example of syntax is quite simple, it should also be possible to simply use StringTokenizer to tokenize and parse these kind of scripts.

If you want to introduce more complex expressions or control structures you probably better choose ANTLR

stacker
+2  A: 

Take a look at Xtext - it will take a grammar definition and generate a parser as well as a fully-featured eclipse editor pluging with syntax highlighting and -checking.

Michael Borgwardt
@Michael, that surely looks nice!
Bart Kiers
+2  A: 

Have a look at how Cucumber defines its test cases:

alt text

http://cukes.info/ - can run in JRuby.

Thorbjørn Ravn Andersen