Search code examples
javacucumberintegration-testingcitrus-framework

citrus-cucumber or citrus/xmlDSL tests


I'm now using citrus framwork integrated with cucumber. I'm thinking to change for the XML DSL (or java DSL). Should I add a template for each different tested file (xml or json)? And to link them ?

My tests should compare two files or more. I can just put the path of theses files ( I saw the examples are just about messages..) ?

Thanks a lot for your help!


Solution

  • In case you want to use Cucumber BDD with Citrus you should go with the Java DSL as it is integrated into writing Cucumber step definition classes. Within the step definition method you can of course load templates from filesystem or classpath. Lets say you have the following line in your BDD specification.

    When user adds entry "path/to/template.txt"
    

    You can use the path in your step definition as method parameter and load the template from filesystem or classpath.

    @When("^user adds entry \"([^\"]*)\"$")
    public void add_entry(String path) {
        designer.http()
            .client(todoClient)
            .send()
            .post("/todo")
            .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
            .payload(new ClassPathResource(path));
    }
    

    Of course you can also do this when receiving and validating messages via file templates.

    In case you go for pure XML tests without Cucumber you can just give the file path in your send/receive operation.

    <testcase name="TodoList_Post_IT">
      <actions>
        <http:send-request client="todoClient">
          <http:POST path="/todo">
            <http:headers content-type="application/x-www-form-urlencoded"/>
            <http:body>
              <http:resource file="path/to/template.txt" />
            </http:body>
          </http:POST>
        </http:send-request>
      </actions>
    </testcase>
    

    This works for Http and all other message transports (JMS, WebSocket, SOAP WebServices, ...).

    You can also use test variables in your template files in order to reuse them in multiple test cases. Have a look at test variables in Citrus they help you to get more dynamic tests data.