I need to generate test cases of cucumbers for an application written in Java.
An example test will look like this:
Scenario My great test Given the following input """ Code snippet of a DSL """ And the following data | name | type | value | | a | Boolean | true | | b | Integer | 5 | When I run the evaluation Then the result should be "Yay!"
I created data types that resemble this structure as a syntax tree, as well as a backend that will take a syntax tree and create a test case line.
Data types are as follows:
data TestCase = Scenario String DslStatement DataStatement ResultStatement data DslStatement = Dsl [TopLevelStatement] data TopLevelStatement = StatementTypeA String | StatementTypeB String | StatementTypeC String SubStatementTypeA [SubStatementTypeB] | StatementTypeD String [String] ...
etc.
Now I want to create many, many of these data structures using different values โโand types and so on.
I could write functions that take the necessary parameters and create a syntax tree with values โโfrom the parameters inserted in the locations that they should appear. However, since the DSL contained in the test case can be changed all the time (it develops gradually), I would have to change all the functions creating the different types of test cases all the time, which is tedious. In addition, test cases can be based on a standard syntax tree, which is modified in only a few places for most test cases.
Now my idea is to create functions that are more or less similar to what would be a designer template with a smooth interface in Java. Starting with the standard syntax tree, I create functions that modify this and return the resulting tree for further change as follows:
withName :: String -> TestCase -> TestCase withName name (Scenario _ dsl data result) = Scenario name dsl data result withResult :: ResultStatement -> TestCase -> TestCase withResult result (Scenario name dsl data _) = Scenario name dsl data result ...
Then I would have to write something like this:
withName "My Test Case" . withResult (Result "Yay!") $ createStandardTestCase
and as soon as the dsl changes should only change the functions of the builder and backend to adapt my test cases.
Is this a possible / valid approach to the problem? Any better ideas for creating such syntax trees?
thanks!
-. Mathias