Always on the lookout for new tools that can help in the testing of APIs, one that I recently found is called Gatling. It is an API performance testing framework written in Scala. We are not currently using it, though I think it would be very beneficial to have in the testing pipeline and is simple to set up.
Comparison to JMeter
JMeter seems to be the go-to for performance testing as it has been around for a while. Being a developer though, I like to code, and that seems to be the big difference between the two frameworks. Gatling is a library that has its own API that you can code to. JMeter has a UI that you use to generate your scripts. Both frameworks have “recording” functionality that you can capture your http events and replay them. However, I think the benefit of code is re-usability and done correctly will allow you to create your scripts much faster, and be more fun in the process.
Below is a short example of a test that authenticates and hits an API for a set of licenses.
In the code above, we have two Objects, Auth and CompanyApi. Auth defines methods for authentication and CompanyApi defines methods around company methods. After we authenticate we store the token in a session map that can be retrieved in additional methods. We also define different “Scenarios” that we want to test. In this case Scenario1 authenticates and makes a call to get a company’s licenses. We store our users’ usernames/passwords in a csv file that a reader will continuously loop over to pass in new users for testing. In the setup section, we tell Gatling to ramp up to 100 users over 5 seconds and that we expect to have 0 failed requests.
Gatling has a plugin for Maven that can generate reports and fail/pass based on the assertions specified.
Learn more about Gatling here. https://gatling.io/