Finding your way around the maze that is JavaScript testing can sometimes be difficult. There are unit tests, integration tests, functional tests, E2E tests, browser tests… With so many buzzwords, who knows what they do and which one to use, what for, and when? To help with that problem, in this article I’ll give you a guide comparing the different …
Unit testing Ajax requests with Mocha
Ajax requests can easily go wrong. You can’t guarantee the connection and the server always work correctly. They are also often used to send user input to the server and back, so it’s vital the data is handled correctly. But testing them can be tricky. It’s asynchronous, and also a good unit test must be isolated, so how can we …
What’s the difference between Unit Testing, TDD and BDD?
When you’re just getting started with automating your JavaScript testing, there’s a lot of questions. You’ll probably see people talk about unit testing, TDD or Test-Driven Development, and BDD or Behavior-Driven Development. But which one of them is the best approach? Can you use all of them? I’ve talked to a number of JavaScript developers, and there seems to be …
How to unit test NodeJS HTTP requests?
I have a nodejs app where I wanted to unit test some HTTP requests. Node usually makes things simple, so I expected this to be like that too… but I soon discovered that this was not the case at all. When unit testing, you don’t want HTTP requests to go out and affect the result. Instead you create a fake …
Why use user story based testing tools like Cucumber instead of other TDD/BDD tools?
When you think of writing tests, usually you would write them using a tool from the xUnit family, PHPUnit, JUnit, etc., or if you like a more BDD-style approach, perhaps you would use RSpec, Jasmine, or some other tool like that. Then there’s Cucumber. Instead of writing your tests purely in code, with Cucumber you start by writing a human-readable …
Headless Chrome/Firefox testing in NodeJS with Selenium and Xvfb
The other day I wanted to run a bunch of tests with a browser in a NodeJS environment. Having been spoiled by how easy it was to do in a Rails setup using Capybara, I thought it would be easy considering how everything cool is easy to do with Node! Well, I thought wrong. It’s easy once you have everything …
How to automatically run unit tests from a git push
Typically when working on code that has tests, you would want to make sure your tests pass when you share your code with other people. It’s generally a good idea to run the tests once in a while too, but why do it manually when you can automate? In this post I’ll show a simple shell script you can use …
Using unit tests as requirements when refactoring
What should you do to make sure new code works properly when you’re refactoring old code? I asked myself this question recently, when I needed to refactor a big bunch of procedural PHP code into a neat, testable, OOP-style interface. The conclusion I came into is that you should write unit tests – not to test the old code, but …
Unit-testing essentials
Here’s some essential unit-testing posts I’ve written recently. While some of them have examples in PHP, they should still be useful in other languages as well. Unit testing PHP series Unit testing introduction Writing and running tests Writing tests for exsisting code Mock Objects and testing code which uses the database Test-driven development General testing topics Unit-testing JavaScript How to …
How to make your code testable
Image by Jim Frazier I’ve recently been working on a code-base which wasn’t designed with test-driven development methodologies, or with unit testing in mind. As I implemented unit-tests to this code, there were some modifications I had to do on the code. Some modifications popped up more than others. There were a few things that are more common than others …