In this post, I will explain to you how I solved integration testing for the Nextcloud News App.

I recently faced the issue that the Nextcloud News App, which I maintain in my free time, only had limited integration testing. Already in place was automated testing of the command line interface of the app, the provided REST API was not tested at all at this point.

The infrastructure

News is a Nextcloud app and therefore requires a web server, PHP and a database. As I mentioned in the beginning, we already had some testing, so I only needed to extend the existing base setup to be able to test the API.

The target

The target was to have simple API testing, to feel more confident that the app would behave as expected. I did not attempt to fully verify all the API details, it was already a big step forward to have some testing.

The solution

As I already mentioned, automation tests for the command line interface were already in place. These tests are running based on bats a Bash based test automation framework.

There was also already code in place to install Nextcloud with all the requirements and to install the News app. The only thing left to do was to have a web server running.

Additionally, I needed a web server that would actually serve the news app. It turned out that the builtin php server was enough to do that.

Since bats is using Bash, everything is quite simple, and you can use the usual bash tricks and tools. Since I had to deal with an API over HTTP, I searched if there was a better tool to talk via HTTP with the API. I found httpie which comes with a simple syntax and all the extras I needed.

The rest was simply writing some test cases and using grep and other tools to verify the results. If you are interested, you can check the code on GitHub.