XF 2.2 Is there an official or recommended way to perform integration test for xenforo addons?

Cylon

Member
Hi!

well the title says it all. I would like to write integration tests for my addon. My addon extends the xf rest api with new endpoints, or adds some new behaviour to existing endpoints, and I would like to be able to tests it with integration tests.
I found something about unit testing in the forum, but I think unit tests are not enough for my case. I would like to do something similar like the following:
  • create a test scenario in maybe an in memory database ( a concrete combination from users, posts, permissions, etc).
  • let a suite of integration tests to perform rest requests to the forum and check if the responses are the expected ones.

Any ideas?
 

Sim

Well-known member
I'm assuming you've already seen this: https://xenforo.com/community/resources/unit-testing-xenforo-addons-tutorial.7508/ ??

The problem with your suggestion is that XenForo only supports MySQL (and variants therein), and has no driver for SQLite or other in-memory database, which makes the ability to run these sort of tests problematic.

The next problem is that booting the entire XenForo framework would be time consuming given how much data is pre-populated into the database at installation time. I guess you could build a snapshot of the database based on a completed new install - but you'd still need to import it every time you built a new instance, which would be time consuming (and memory consuming!!).

The best I can suggest is to isolate as much of your fuctionality as possible into testable components - for example, hide your database calls behind a repository layer and then mock that repository when unit testing so the database never gets hit.

It has crossed my mind to look at building an SQLite driver for XenForo - but I suspect there's quite a bit of MySQL-specific code in the codebase which would make that very hard work, if not impossible.

I'd be keen to hear anyone else's thoughts on how to approach integration testing.

For testing API calls, I use Postman to query against a development instance - but it requires care because I'm not resetting the database between calls, so it's a very manual process.
 

Cylon

Member
Hi, thank you for your answer. Yes, I already know the page you linked in your post.

The thing is that for my needs, the unit tests would not be of much help. It would be more much more useful to be able to test the forum/backend as a black box, also, integration tests.

For example, my addons extends the functionality of some api calls, by adding custom information. I would like to write an integration test that does a rest call, and checks that the expected information is there, to avoid Regresion errors when adding new functionality, or when the forum is upgraded, etc.

Well I will think about it, maybe I find a solution myself

Thankyou anyway.
 
Top