Automated Testing with Codeception & Grunt
81K views
Feb 15, 2023
This is a quick instructional video of how to get Grunt to automatically re-run your unit tests whenever you change a file in your tests directory. There are full instructions on how to make this work (on Ubuntu) right here: https://github.com/a6software/Helpful/tree/master/grunt_automated_testing_config
View Video Transcript
0:00
Hi, I'm Christopher Moss from A6 Software and in this video I'm going to demonstrate how you can use Grunt, the JavaScript Task Runner, for automating the running of our test suite whenever we make a change to one of our test files
0:14
And what you can see in the background here is actually the automated tests in progress, but to get that all set up and working, we're going to need to install Grunt
0:23
and I've demonstrated how to do this in an instruction file, but the rest of this video will basically show the full installation process
0:31
and taught you through how to install it using my GitHub-based instructions
0:37
So it's at GitHub.com forward slash ASIC software, then it's in a folder called Helpful
0:42
and then in a folder called Grunt Automated Testing Config. And as you can see, it's all there, just literally copy and paste it in
0:49
The only thing to really be aware of is if you've got an older
0:53
version of Ubuntu, you will probably need to do an app to get update and then an app to get upgrade
1:00
The reason being otherwise NPM, so Node Package Manager, will more than likely throw an error
1:07
unless you've got that installed, sorry, unless you've updated your Ubuntu server installation
1:13
to one of the later versions. The main reason to do this really is to save time
1:18
So when you're testing, it can be a little bit tedious to keep going back and forth
1:23
to the console, rerunning the command every time that you make a file change save
1:27
or file save. And then really what you want to do is have those tests running constantly so you know when things are breaking or you know it that constant feedback loop that you getting now there are downsides to doing something like this if you got heavily if your tests heavily use the database this can lead to situations where the reloading of the fixtures every time that you hit command s or control s you can end up obviously getting into a situation where you
2:00
tests are sort of not even finished running before you've hit ControlS again because you might
2:05
have made a typo or something. And that can cause your machine to go a little bit stir crazy
2:11
as it's trying to catch up. So what I would advise is you don't really run this against
2:16
heavily database intensive test files, nor would I really run it to trigger the acceptance
2:23
tests either. That can be something that can be done with like a Git hook, but that's not really
2:28
what we're trying to achieve here. But what I would say is whenever you're doing heavy unit
2:34
testing, this can be really useful. And really your unit tests shouldn't be hammering the database
2:39
anyway. You should try and mock off any calls to the database as, you know, you're only testing
2:45
the individual unit at the end of the day. You're not testing that there's a database there
2:50
That's not to say in the real world, that doesn't happen, but it is something that's going to
2:54
dramatically slow your tests down. So if you're going to do a lot of database
2:58
heavy testing that this perhaps wouldn't be the best solution but for a lot of just general unit
3:03
testing or maybe just unit testing one specific module that you're working on this can be a real
3:08
time saver and i hope you've enjoyed it