Test Automation & CI/CD integration

Testing is a crucial part of any development process. However, it is often overlooked. Be it because the developer overlooked it or they simply forgot about it. This may save time at the moment, but it can lead to headaches down the line.

Thus it makes sense to automate the testing of new builds and have this automated testing as a part of your CI/CD pipeline. In this guide, we will show you how easy it is to automate the testing of new builds using the Simulation APIs on IoTIFY.

Before we can run a test, first we need to write the test which models the behaviour of the device or usage. For this, simply navigate to IoTIFY and create a new test. If you are not familiar with tests on IoTIFY, you can follow the guide linked below.

Understanding Tests

Now that we have our test ready, we can use the Simulation APIs to start and monitor the results of this test. However, before we can start using the APIs, we need to generate an API key which we will use to authorise these API calls.

Navigate to IoTIFY and click on the settings in the lower left corner. This will take you to your account settings.

Here, click on API Keys in the left menu. This will open the API keys page, here you can see your already provisioned API keys and also create new ones. To create a new API key, click on the Create New button in the top-right corner of the screen. A new API Key will be created and displayed on the page.

Now you are ready to use the APIs. You can go to the page linked below to get more details about the APIs. Here we will use simple curl commands to call these APIs.

Simulation API

Run the following curl command below to start a test via the API. Here replace $KEY with the API key, $JOBNAMEwith the any name for the job (this has to be unique) and $TESTID with the test you want to run. You can also change the runsettings parameters as required with the clients and iterations.

curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "key:$KEY" -H "domain:nsim.iotify.io" -d '{"jobName":"$JOBNAME","runSettings":{"interval":1000,"iteration":150,"clients":10,"totalClients":5,"clientIdOffset":0}}' nsim.iotify.io/api/test/$TESTID/run

The command will return a success along with a job ID which we will use to check the status of that job.

Run the following curl command to get the current status of a running job. Here replace $KEY with the API key, $WORKSPACE with the workspace ID and $JOB with the job ID.

curl -X GET -H "Accept: application/json" -H "Content-Type: application/json" -H "key:$KEY" -H "domain:nsim.iotify.io" nsim.iotify.io/api/jobs/$WORKSPACE/$JOB

The command will return an object with the results and status of the job.

So now you can use the Simulation APIs from IoTIFY to automate your testing and make your CI/CD pipeline more robust.

Last updated