Automation Testing

Citrus API Automation Testing Framework

By Test Guild
  • Share:
Join the Guild for FREE
Citrus Automation Framework

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.

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

SafeTest: Next Generation Testing Framework from Netflix

Posted on 03/26/2024

When you think of Netflix the last thing you probably think about is ...

Top Free Automation Tools for Testing Desktop Applications (2024)

Posted on 03/24/2024

While many testers only focus on browser automation there is still a need ...

Bridging the Gap Between Manual and Automated Testing

Posted on 03/13/2024

There are some testers who say there’s no such thing as manual and ...