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.
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.
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.
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.
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:
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?
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.
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.