0Pricing
Edge Computing with Cloudflare Workers & Deno · レッスン

Denoアプリケーションのテスト

組み込みのテストランナー、アサーション、モックを使ってDenoアプリのテストを記述・実行し、信頼性の高いエッジコードを作成します。

「Denoアプリケーションのテスト」はCoddyKit上の無料Edge Computing with Cloudflare Workers & Denoレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはEdge Computing with Cloudflare Workers & Deno学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Edge Computing with Cloudflare Workers & Denoコースには全4レッスンが含まれています。

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

Built-in Testing

Deno ships with a built-in test runner — no extra framework or config needed. Just write tests and run deno test.

Your First Test

Register a test with Deno.test. It takes a name and a function.

Deno.test('adds numbers', () => {
  const sum = 2 + 3;
  if (sum !== 5) throw new Error('wrong');
});

The Assertions Module

Use the standard library's assertions for clearer failures instead of manual throws.

import { assertEquals } from 'jsr:@std/assert';

Deno.test('math', () => {
  assertEquals(2 + 3, 5);
});

Running Tests

Run all tests in your project. Deno discovers files ending in _test.ts or .test.ts automatically.

deno test
deno test --allow-net

Async Tests

Tests can be async — just return a promise or mark the function async. Deno awaits it before reporting.

Deno.test('fetches data', async () => {
  const res = await fetch('https://example.com');
  assertEquals(res.status, 200);
});

Test Steps

Break a complex test into named steps with t.step for clearer output and partial results.

Deno.test('user flow', async (t) => {
  await t.step('signup', () => {});
  await t.step('login', () => {});
});

Permissions in Tests

Tests obey Deno's permission model. A test needing network access fails without --allow-net, so you test real security boundaries.

Mocking & Spies

The std testing module provides spies, stubs, and mocks to isolate units from external services.

import { spy } from 'jsr:@std/testing/mock';
const log = spy(console, 'log');

Snapshot Testing

Deno's assertSnapshot stores expected output and compares future runs against it — great for stable structured responses.

Coverage Reports

Measure how much code your tests exercise with the built-in coverage tools.

deno test --coverage=cov
deno coverage cov

Testing Edge Logic

Structure handlers as pure functions of a Request so you can test them without a running server — ideal for edge code.

export function handler(req: Request) {
  return new Response('ok');
}

Quick Check

Test your Deno testing knowledge.

Recap

You learned to write tests with Deno.test, use std assertions, handle async and steps, respect permissions, mock dependencies, and measure coverage — keeping your edge code reliable.

よくある質問

「Denoアプリケーションのテスト」レッスンは無料ですか?

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

「Denoアプリケーションのテスト」で何を学びますか?

組み込みのテストランナー、アサーション、モックを使ってDenoアプリのテストを記述・実行し、信頼性の高いエッジコードを作成します。 ブラウザで直接実行するハンズオンコードでEdge Computing with Cloudflare Workers & Denoを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Edge Computing with Cloudflare Workers & Denoを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのEdge Computing with Cloudflare Workers & Denoは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「Denoアプリケーションのテスト」レッスンにはどのくらい時間がかかりますか?

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

このEdge Computing with Cloudflare Workers & Denoレッスンでコードを書いて実行できますか?

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

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

  1. Denoランタイムの基本
  2. モジュールシステムと権限
  3. ローカルDenoアプリの開発
  4. Denoアプリケーションのテスト
← Edge Computing with Cloudflare Workers & Denoに戻る