Automation Testing

Citrus API Automation Testing Framework

By Test Guild
  • Share:
Join the Guild for FREE

How often have you heard about the testing pyramid and about how more tests should be at the lower levels?

If you’re like me, probably many.

And I 100% agree with creating fewer UI tests.

But if you look online, almost all of the open source frameworks you’ll find are based on UI browser-based test automation. It’s hard to find tools that allow you to test beyond the UI.

I’m a big believer in testing functionality beyond the user interface (UI) whenever possible. And since integration/API tests bypass the UI, they tend to be quicker and much more reliable than GUI tests.

Furthermore, when looking for an automation testing framework, most folks forget to include API testing as a prerequisite when looking for a test tool for their team.

That’s why I was happy to recently discover the Citrus Framework after speaking with its creator, Christoph Deppisch, on TestTalks.

What is Citrus Automation at a High Level?

Citrus is an open-source framework that can help you automate integration tests for virtually any messaging protocol or data format.

If you have a test flow that requires your application to interact with other services, then APIs and components using functional test tools such as Selenium can’t help.

However, if you’re using a messaging transport such as HTTP, REST, SOAP or JMS, Citrus is the framework of choice to test your applications messaging integrations.

How are Citrus API Automation Tests Created?

There are two ways you can create automated integration tests with Citrus:

1. XML – You can write your test case without having to write Java code at all. You can simply code it in XML.

2. Java – The more popular option is using the Citrus fluent API in Java to write your Citrus test case as you would a standard Java unit test, for example.

Think of a Citrus test case as being like a JUnit test or a TestNG test that also has Citrus capabilities.

This allows you to add Citrus to your development frameworks and use languages like Java or Scala for your tests.

This flexibility allows your non-programmer engineers to create tests by using the XML way of writing a Citrus test case.

rest-assured

Automating REST Services

Of course, one of the more common testing scenarios in Citrus is the ability to test REST services.

Citrus has REST's extensions and supports all the standard Rest requests, including:

  • POST
  • GET
  • PUT
  • DELETE
  • OPTIONS
  • PATCH
  • HEAD

When you get a response, you can then validate that the correct status code (like 200 OK or 404 Not Found) is returned from your request.

Automating Web Service Tests

As I mentioned earlier, unlike other frameworks that tend to only focus on REST tests, Citrus can also test the older style, SOAP-based Web services. So it contains all the functionality you would also need to test your SOAP APIs.

But remember—one of the coolest thing about Citrus is that you can test both a REST service and a SOAP service in one Citrus test.

But…what if you also need to test a UI component using Selenium and make an API request?

No problem!

Citrus and Selenium Testing End-to-End Workflows

Citrus also integrates with Selenium, which is handy if you need to interact with a user interface and then verify a back-end process. For example, say you had to click on a “send email” button and confirm on the back end that the email was received.

Citrus can receive this email or the JMS communication triggered by the UI and verify the back-end results all in one test.

In this way, Citrus gives you true end-to-end test coverage that you can’t get with a GUI test tool.

Also So Citrus is not focused on just using Rest-APIs, HTTP or just using JMS it can test all kinds of messaging Transport's with different services in the same tests.

So in the same tests, you can send out some HTTP call, and then you can receive email and then you can receive a file via FTP communication and so on.

Ultimately the big problem Citrus solves is to have messaging integration with different messaging transport at the same time in the same test flow.

BDD API Testing with Citrus

Citrus also works with BDD.

There's a Citrus BDD extension that works on top of Cucumber so that you can use the components and fluent API of Citrus inside of Cucumber tests.

There are some tools for REST-based testing that integrate with Cucumber—Karate DSL, for one—but what if you have test flows that also need to interact with JMS SOAP or other headless technologies?

If you need to create these types of test flows, Citrus is a lifesaver.

How to Succeed with Integration Automation Testing

Christoph made an excellent point near the end of our interview that applies to any integration testing you need to do–regardless of what tool you use.

You have to write your integration tests so they can be automated.

Too many people write integration tests that require some kind of manual interaction that must be performed (preparing the testing environment or manually setting something’s state, for instance).

Don’t do this!

Write your integration tests so that they can be automated and integrated into your continuous delivery.

Try to automate entirely from one end to the other end. Only then can your tests be executed in a reliable, frequent, automated way.

Check Out Citrus Framework

For more info make sure to check out the Citrus Framework user guide – their documentation is actually really good.

  1. Totally agree how we need to start doing more automation at levels lower than the UI. Integration tests and unit tests are faster and drastically more reliable than UI automation. I’ve spent my career trying to get my UI tests as stable as unit tests and it simply isn’t happening. Either way, this tool seems great. Wish they had something similar for C#. The Java people are spoiled :)

  2. LOL I agree – I hate Java but use it because there are so many libraries and tools that use it. i would rather use python or even C# over Java myself :)

  3. I’m the author of Karate DSL and while I appreciate the mention in this article, it is somewhat inaccurate and misleading. I quote:

    > There are some tools for REST-based testing that integrate with Cucumber
    > Karate DSL, for one—but what if you have test flows that also need to interact
    > with JMS SOAP or other headless technologies?

    First, Karate has excellent support for SOAP and XML. And, Karate not only has test-doubles (or mocks) as a first-class citizen of the framework, but if you follow the link here, the demo integrates ActiveMQ (JMS): https://github.com/intuit/karate/tree/master/karate-netty#consumer-provider-example

  4. Looks interesting.
    Joe, I did not know about Citrus Automation prior to this TestTalk episode.
    Will check this out more deeply.

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

DevAssure Review: Cut Testing Time Using Low Code Automation?

Posted on 12/11/2024

As you know, testing often becomes a bottleneck in software development due to ...

Leveraging AI and Playwright for Test Case Generation

Posted on 11/22/2024

Two BIG trends the past few years in the software testing space been ...

Symbolic AI vs. Gen AI: The Dynamic Duo in Test Automation

Posted on 09/23/2024

You've probably been having conversations lately about whether to use AI for testing. ...