Closed garethsime closed 4 months ago
I've been playing around with how to get started writing tests for Librivox for a little while. ci-phpunit-test came up in a lot of my searches, so I gave it a go, and I thought I'd share what I learned and propose that it gets added to librivox-catalog.
So far, it's been pretty good. It was pretty easy to install (both manually and via composer, I don't know if you have a preference). I've used it to write tests while working on a couple of PRs, and I've included some of them below.
I'm a huge fan of TDD, automated testing, and CI, so I love this :) I wish the code had proper testing from the beginning, but this is a start on retroactively adding tests, which will in turn allow us to change things with more confidence that we aren't breaking something else.
One thing to be wary of is that it looks like the project hasn't had a lot of activity lately, but I think that's going to be the case with pretty much any CodeIgniter 3.x library. (The library maintainer's recommendation is that we upgrade to CodeIgniter 4, but that looks like it might be a big piece of work and I don't know what plans there are for it, if any.)
Moving to CI 4, while not crazy, is not trivial either. The original author of the code base is long gone, so one really knows how all of it works. Just moving to CI3 from CI2 was a whole thing, and that mostly didn't require rewriting stuff. My opinion is that we'll get more value out of adding tests for stuff, than moving to CI4.
Now that this PR is merged, I'd love to see it run in GitHub Actions. The slight wrinkle is that it needs to run in a "deployed" repository, with the configs and database in place, so we can't just check out this repo and run pphunit
:( If we can somehow leverage https://github.com/LibriVox/librivox-ansible/blob/master/.github/workflows/deploy-localdev.yaml to get CI on this repo, I'd be really happy.
It took me an embarrassingly long amount of time chasing down the wrong things (GitHub refs) before realizing I was getting bit by Ansible variable precedence, but we can now run unit tests on PRs in CI!
Oh wow, that's awesome! Thanks for putting in all the hard work, it looks great 🙂
(Maybe I'll have to learn how LXC works now haha)
I've been playing around with how to get started writing tests for Librivox for a little while. ci-phpunit-test came up in a lot of my searches, so I gave it a go, and I thought I'd share what I learned and propose that it gets added to librivox-catalog.
So far, it's been pretty good. It was pretty easy to install (both manually and via composer, I don't know if you have a preference). I've used it to write tests while working on a couple of PRs, and I've included some of them below.
One thing to be wary of is that it looks like the project hasn't had a lot of activity lately, but I think that's going to be the case with pretty much any CodeIgniter 3.x library. (The library maintainer's recommendation is that we upgrade to CodeIgniter 4, but that looks like it might be a big piece of work and I don't know what plans there are for it, if any.)
Note: Most of the files here are boilerplate/config and were generated by following the install instructions.
Example from pull-request #186
Here's an example from checking that accessing
/author/0
returns a 404 and that searching for authors usingprimary_key=0
returns a 400:Example from pull-request #189
And here's an example test that I wrote to check that we were normalising and squashing down newlines correctly:
Some sample output when the tests pass:
Some sample output when the tests fail: