As one of the five major test types supported on our platform, RedLine13 offers the ability to run your k6 load tests in the cloud. Tests are defined in k6 using the JavaScript syntax, centered around simplicity and extensibility. It is a developer-centric performance testing tool that affords scalability to test designers for scripting, execution, and analysis of load tests. Since it was introduced, k6 has steadily risen in popularity to become one of the de facto standards in performance testing alongside JMeter. With RedLine13, you can run cost-effective k6 load tests that scale in the cloud.
Running a k6 Load Test on RedLine13
On the “Start Test” page, you will find a “k6” tab as one of the available test types:
From there, you will need to have your k6 test plan, which is typically a JavaScript file. In this article, we will show some examples of k6 plans and how to create your own. Once you have prepared your test plan file, you can then configure your test on RedLine13:
You can find the complete details about creating a k6 test plan (including all available options) in the RedLine13 Owner’s Manual.
How to Create a k6 Test Plan
You can find many examples of k6 tests within the official k6 documentation. This is a good starting point if you are new to k6. Here is one example from that illustrates making a basic web request from k6:
import http from “k6/http”;
export const options = {
iterations: 1,
};
export default function () {
const response = http.get(“https://test-api.k6.io/public/crocodiles/”);
}
This example makes a single HTTP request to the specified endpoint using the http.get()
method. Comparing this with JMeter, this is equivalent to a single HTTP Request sampler inside a basic thread group running one iteration. While JMeter uses a GUI to create test plans, k6 uses a code-based approach. Though code-based scripts are preferred, there is a graphical Test Builder tool available which can assist with test plan creation.
Once your test plan is created, it should be saved as a JavaScript file (*.js
). From there, it can be uploaded to RedLine13 using the steps outlined above.
Accelerate Prototyping your k6 Tests
As mentioned above, the k6 documentation pages have many examples of both basic tests, and common real-world test scenarios. If your test needs to incorporate any of these common tasks, you can use these templates as building blocks to accelerate the creation of your own tests. Here are some examples of common test cases that can you can utilize:
- Common HTTP methods such as GET and POST – this covers use cases of the http module, a core functional feature of k6 tests
- Code examples for test lifecycle – you can find examples for common operations which control the flow of your k6 test
- Importing common modules – one of the key features of k6 is extensibility, and the ability to import both built-in modules and user-defined modules
- Validation checks – k6 supports boolean validation checks to control flow within your load test
- Specifying k6 test options – highlights essential options for most k6 tests, with reference to all available options
In addition to these reference examples provided, another useful tool for rapid prototyping of your k6 tests is with a generative AI tool such as ChatGPT. In a previous post, we covered how to use ChatGPT to assist in the creation of JMeter tests. The same principles can be applied to creating either the basic structure or component parts of your k6 tests. Here is an example prompt we can provide to ChatGPT to assist with k6 script creation:
In expected fashion, ChatGPT quickly and enthusiastically creates the basic structure for our k6 test, and provides instructions on which constants and variables to replace in order to adapt this example to our intended use case:
The full script that ChatGPT has generated is as follows:
import http from ‘k6/http’;
import { check, sleep } from ‘k6’;
export let options = {
vus: 10, // Number of virtual users
duration: ’10s’, // Duration of the test
};
export default function () {
// Define the payload (username and password)
let payload = {
username: ‘testuser’,
password: ‘testpassword’,
};
// Make a POST request to the form endpoint with the payload
let response = http.post(‘https://your-app-url.com/login’, payload);
// Check if the response status is 200 (OK)
check(response, {
‘Status is 200’: (r) => r.status === 200,
});
// Add a sleep to simulate user think time
sleep(1);
}
Using the “Copy code” option, the generated response from ChatGPT can be saved to a local file, which can be uploaded and run in the cloud using RedLine13.
Did you know that RedLine13 offers a full-featured time-limited free trial? Sign up now, and start testing with k6 in the cloud today!