0Pricing
Load Testing & Performance Benchmarking (JMeter & k6) · レッスン

k6のインストールとCLI

k6をインストールし、テスト実行に使用するコマンドラインインターフェースに慣れます。

「k6のインストールとCLI」はCoddyKit上の無料Load Testing & Performance Benchmarking (JMeter & k6)レッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLoad Testing & Performance Benchmarking (JMeter & k6)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Load Testing & Performance Benchmarking (JMeter & k6)コースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Meet k6: Load Testing Tool

Welcome! In this lesson, we'll get started with k6, a powerful open-source load testing tool. k6 is built with Go and allows you to write performance tests using JavaScript.

It's designed for developers and QA engineers who want to integrate performance testing into their modern development workflows.

Why Choose k6?

k6 offers several advantages for performance testing:

  • JavaScript API: Write tests in familiar JavaScript.
  • CLI-focused: Easy to integrate into CI/CD pipelines.
  • Performance: Built on Go, it's efficient and fast.
  • Modern Approach: Treats performance tests as code, enabling version control and code reviews.

Installation Overview

Before we write our first test, we need to install k6 on your system. k6 supports various operating systems like Windows, macOS, and Linux.

The recommended way to install k6 is through package managers, which makes the process straightforward and quick.

macOS and Linux Setup

For macOS users, the easiest way to install k6 is using Homebrew. Open your terminal and run:

brew install k6

On Debian/Ubuntu Linux, you can install k6 from its official repository with these commands:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E34A0A echo "deb https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list sudo apt update sudo apt install k6

Windows Installation

Windows users have a couple of easy options using popular package managers.

Using Chocolatey (run in an elevated PowerShell or CMD):

choco install k6

Using Scoop (run in PowerShell):

scoop install k6

Check Your k6 Version

After installation, it's important to verify that k6 is correctly installed and accessible from your command line. Open a new terminal or command prompt and type:

k6 version

You should see the installed k6 version number displayed, confirming a successful setup.

The `k6 run` Command

The core of k6 is its powerful Command Line Interface (CLI). The most frequently used command is k6 run.

This command is used to execute your k6 test scripts. You simply point it to your JavaScript file, and k6 takes care of the rest.

k6 run your_script.js

A Minimal k6 Test

Let's create a super simple k6 script. This script will make a single HTTP GET request to example.com. We'll save this as script.js.

Notice the import http statement – k6 provides built-in modules like http for making requests.

import http from 'k6/http';
import { sleep } from 'k6/execution';

export default function () {
  http.get('https://test.k6.io');
  sleep(1);
}

Run Your k6 Test

Now that you have your script.js file, open your terminal in the same directory where you saved the file. Then, execute the script using the k6 run command:

k6 run script.js

k6 will execute the test, and you'll see output in your terminal showing metrics like requests, duration, and checks.

Customizing Your Run

The k6 run command supports various options to customize your test. Two common ones are:

  • --vus: Sets the number of Virtual Users.
  • --duration: Defines how long the test should run.

For example, to run with 5 VUs for 10 seconds:

k6 run --vus 5 --duration 10s script.js

CLI Command Check

You've learned how to install k6 and run a basic script. Let's test your understanding of the essential k6 CLI command.

k6 Ready: What's Next?

Fantastic! You've successfully installed k6 and run your very first performance test script. We covered:

  • What k6 is and its benefits.
  • How to install k6 on different operating systems.
  • Verifying your installation.
  • Using the essential k6 run command to execute a JavaScript test script.

In the next lesson, we'll dive deeper into writing more complex k6 scripts and understanding their structure.

よくある質問

「k6のインストールとCLI」レッスンは無料ですか?

はい。「k6のインストールとCLI」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Load Testing & Performance Benchmarking (JMeter & k6)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Load Testing & Performance Benchmarking (JMeter & k6)コースには全4レッスンが含まれています。

「k6のインストールとCLI」で何を学びますか?

k6をインストールし、テスト実行に使用するコマンドラインインターフェースに慣れます。 ブラウザで直接実行するハンズオンコードでLoad Testing & Performance Benchmarking (JMeter & k6)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Load Testing & Performance Benchmarking (JMeter & k6)を始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLoad Testing & Performance Benchmarking (JMeter & k6)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「k6のインストールとCLI」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLoad Testing & Performance Benchmarking (JMeter & k6)レッスンでコードを書いて実行できますか?

はい。すべてのLoad Testing & Performance Benchmarking (JMeter & k6)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. k6のインストールとCLI
  2. 基本的なk6スクリプトの作成
  3. Checks、Thresholds、Metrics
  4. テスト整理のためのグループとタグ
← Load Testing & Performance Benchmarking (JMeter & k6)に戻る