Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Electron Debugging and Testing

Electron Debugging and Testing

Electron apps involve main process and renderer process two runtime environments, so debugging and testing strategies need to be designed for different processes.
A good debugging and testing workflow can improve development efficiency and app stability.


Debugging the main process

Debugging with Chrome DevTools

VS Code breakpoint debugging

}

Logging


Debugging the renderer process

Opening developer tools

mainWindow.webContents.openDevTools()

Remote debugging

electron --remote-debugging-port=9223 .

React / Vue DevTools

npm install --save-dev electron-devtools-installer

app.whenReady().then(() => { installExtension(REACT_DEVELOPER_TOOLS) .then(name => console.log(已安装: ${name})) .catch(err => console.log('Installation failed:', err)) })


Automated testing

Spectron testing framework

const assert = require('chai').assert const path = require('path')

describe('App Startup Test', function () { this.timeout(10000) let app

before(async () => { app = new Application({ path: require('electron'), // Electron executable file args: [path.join(__dirname, '..')] }) await app.start() })

after(async () => { if (app && app.isRunning()) await app.stop() })

it('Window count should be 1', async () => { const count = await app.client.getWindowCount() assert.equal(count, 1) }) })

Unit testing

End-to-end testing

CI/CD Integration

Configure Electron tests in continuous integration platforms (GitHub Actions, GitLab CI):


Summary

Key points of Electron debugging and testing: