Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Testing Electron App | Electron.js Desktop App Development l | BraveProgrammer
  1. Courses
  2. /
  3. Electron.js Desktop App Development

Lesson 18 of 28

·javascript

Testing Electron Apps – Spectron & Playwright

11 mins

Course progress64%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Spectron is the original Electron test framework; Playwright is the recommended modern alternative.
  • Use **E2E tests** to verify window creation, menus, and IPC interactions.
  • Unit‑test the main process like any Node module (Jest/Mocha).
  • Run tests in CI by launching Electron with `--headless` or using Playwright’s headless mode.

Testing Electron Apps – Spectron & Playwright

Spectron (official but now deprecated)

npm install --save-dev spectron mocha
const { Application } = require('spectron');
const assert = require('assert');

describe('App launch', function(){
  this.timeout(10000);
  let app;
  beforeEach(()=>{ app = new Application({ path: require('electron'), args: ['.'] }); return app.start(); });
  afterEach(()=> app && app.stop());

  it('shows a window', async()=>{ const count = await app.client.getWindowCount(); assert.equal(count, 1); });
});

Playwright (modern, cross‑platform)

npm install --save-dev @playwright/test electron
// tests/electron.test.js
const { test, expect } = require('@playwright/test');
const { _electron: electron } = require('playwright');

test('app has title', async () => {
  const app = await electron.launch({ args: ['.'] });
  const window = await app.firstWindow();
  await expect(window).toHaveTitle(/MyApp/);
});

Playwright can also record videos and run headless CI.

Unit testing the main process

Use any Node test runner (Jest, Mocha) because the main process is just a Node script.

// main.test.js
const { app } = require('electron');
test('app is not null', () => { expect(app).toBeDefined(); });
Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Electron.js Desktop App DevelopmentBrowse activities
Previous lessonDebugging – DevTools, Remote Debugging & LoggingContinue to lesson 19Performance Profiling – Chrome DevTools & Electron‑PerformanceBack to Electron.js Desktop App Development curriculum