本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペースはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらく

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシープライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
012345678901234567890123456789012345678901234567890123456789
昨日
012345678901234567890123456789012345678901234567890123456789
累計閲覧
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

Electron ドキュメント
Electron
Getting Started with ElectronProject StructureCore ConceptsData and StateTestingDeployment
ディスカッション

Electron ガイド · 5/6

Testing

この章は現在、英語でのみ提供しています。

An Electron app has a main process, preload scripts, and renderers working together, so no single kind of test covers everything. This chapter shows how to unit test logic that does not depend on Electron, and how to write end-to-end (E2E) tests with Playwright that launch the real app and drive its windows.

A testing strategy

KindTargetTools
Unit testsPure functions, data transforms, validationVitest, Jest
Module testsMain process code that calls Electron APIsVitest with a mocked electron
Renderer component testsReact or Vue componentsYour UI framework's testing tools
E2E testsThe whole running appPlaywright, WebdriverIO

The first step toward a testable app is to separate business logic from Electron APIs. Rather than writing long logic inside IPC handlers, extract it into pure functions and have the handlers simply call them.

Unit testing pure logic

Take a function that maintains a recent-files list. It knows nothing about Electron, so plain Node.js tests can check it.

// src/lib/recent-files.js
export function addRecentFile(list, file, max = 10) {
  return [file, ...list.filter((item) => item !== file)].slice(0, max)
}
npm install --save-dev vitest
npx vitest
// tests/recent-files.test.js
import { describe, it, expect } from 'vitest'
import { addRecentFile } from '../src/lib/recent-files'

describe('addRecentFile', () => {
  it('puts a new file first', () => {
    expect(addRecentFile(['a.txt'], 'b.txt')).toEqual(['b.txt', 'a.txt'])
  })

  it('moves an existing file to the front', () => {
    expect(addRecentFile(['a.txt', 'b.txt'], 'b.txt')).toEqual(['b.txt', 'a.txt'])
  })

  it('never exceeds the maximum length', () => {
    expect(addRecentFile(['a', 'b', 'c'], 'd', 3)).toEqual(['d', 'a', 'b'])
  })
})

Mocking the electron module

In plain Node.js, require('electron') returns the path to the Electron executable as a string, not the API. To load main process code in a Node.js test runner, replace the electron module with a mock.

// src/main/settings-path.js
import { app } from 'electron'
import path from 'node:path'

export const settingsPath = () => path.join(app.getPath('userData'), 'settings.json')
// tests/settings-path.test.ts
import { vi, it, expect } from 'vitest'
import path from 'node:path'

vi.mock('electron', () => ({
  app: { getPath: vi.fn(() => '/tmp/test-user-data') },
}))

import { settingsPath } from '../src/main/settings-path'

it('points at settings.json under userData', () => {
  expect(settingsPath()).toBe(path.join('/tmp/test-user-data', 'settings.json'))
})
この章について質問がありますか?
前の章Data and State次の章Deployment

vi.mock is hoisted to the top of the file, so it takes effect before the imports below it. Note that Vitest mocks apply to modules that Vitest itself transforms and loads, not to CommonJS modules that Node.js loads directly through require. That is why the main process code above uses ES module syntax, which comes naturally in projects that bundle the main process, such as the Forge Vite and webpack templates.

End-to-end tests with Playwright

Playwright has experimental support for launching and controlling Electron apps. _electron.launch() starts your app and returns an ElectronApplication; from it you get windows as regular Page objects and drive them like any web test. evaluate() runs code inside the main process.

npm install --save-dev @playwright/test
npx playwright test
// tests/app.spec.ts
import { test, expect, _electron as electron } from '@playwright/test'

test('opens the main window', async () => {
  const electronApp = await electron.launch({ args: ['main.js'] })

  // Runs in the main process
  const isPackaged = await electronApp.evaluate(async ({ app }) => app.isPackaged)
  expect(isPackaged).toBe(false)

  const window = await electronApp.firstWindow()
  await expect(window).toHaveTitle('Hello Electron')
  await expect(window.locator('h1')).toHaveText('Hello from Electron')

  await electronApp.close()
})

Native dialogs cannot be automated, so swap out the dialog functions in the main process from inside the test.

test('opens a file', async () => {
  const electronApp = await electron.launch({ args: ['main.js'] })
  await electronApp.evaluate(({ dialog }, filePath) => {
    dialog.showOpenDialog = async () => ({ canceled: false, filePaths: [filePath] })
  }, '/tmp/sample.txt')

  const window = await electronApp.firstWindow()
  await window.getByRole('button', { name: 'Open' }).click()
  await expect(window.locator('#file')).toHaveText('/tmp/sample.txt')
  await electronApp.close()
})

To test a packaged build, pass the path of the built executable as electron.launch({ executablePath: '...' }).

Running in CI

Linux CI machines have no display, so Electron windows need a virtual one.

# Ubuntu example
sudo apt-get install -y xvfb
xvfb-run --auto-servernum npx playwright test

WebdriverIO also supports Electron E2E testing through its Electron service (wdio-electron-service). Spectron, which older guides mention, is no longer maintained and should not be used for new projects.

Summary

  • Pull business logic out of Electron APIs into pure functions and unit test them with Vitest or Jest.
  • Mock the electron module when loading main process code in a Node.js test runner.
  • Use Playwright's _electron.launch() to start the real app, drive its windows, and inspect the main process with evaluate().
  • Provide a virtual display with xvfb-run on Linux CI.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。