close
logologo
Guide
Config
Plugin
API
Community
Version
Changelog
Rsbuild 0.x Doc
English
简体中文
Guide
Config
Plugin
API
Community
Changelog
Rsbuild 0.x Doc
English
简体中文
logologo

Getting Started

Introduction
Quick start
Features
Glossary

Framework

React
Vue
Preact
Svelte
Solid

Basic

CLI
Dev server
Output files
Static assets
HTML
JSON
Wasm
TypeScript
Web Workers
Deploy static site
Upgrade Rsbuild

Configuration

Configure Rspack
Configure Rsbuild
Configure SWC

Styling

CSS
CSS Modules
CSS-in-JS
Tailwind CSS v4
Tailwind CSS v3
UnoCSS

Advanced

Path aliases
Environment variables
Hot module replacement
Browserslist
Browser compatibility
Module Federation
Multi-environment builds
Server-side rendering (SSR)
Testing

Optimization

Code splitting
Bundle size optimization
Improve build performance
Inline static assets

Migration

Migrating from Rsbuild 0.x
webpack
Create React App
Vue CLI
Vite
Vite plugin
Modern.js Builder

Debug

Debug mode
Build profiling
Use Rsdoctor

FAQ

General FAQ
Features FAQ
Exceptions FAQ
HMR FAQ
📝 Edit this page on GitHub
Previous PageServer-side rendering (SSR)
Next PageCode splitting

#Testing

Rsbuild doesn't include built-in testing frameworks, but integrates seamlessly with popular testing tools.

This guide will introduce how to add unit testing and end-to-end testing to Rsbuild applications.

#Unit testing

Unit tests verify individual components and functions in isolation. Rsbuild can work with testing frameworks like Rstest, Vitest, Jest, and others.

The following example uses Rstest to demonstrate how to add unit testing to a Rsbuild application.

#Rstest

Rstest is a testing framework built on Rsbuild that provides first-class support for Rsbuild applications. It offers Jest-compatible APIs while natively supporting modern features like TypeScript and ESM.

#Installing

npm
yarn
pnpm
bun
npm add @rstest/core -D

#Configuring scripts

Add test scripts to your package.json:

{
  "scripts": {
    "test": "rstest",
    "test:watch": "rstest -w"
  }
}

#Writing tests

Create test files, for example:

src/utils.ts
export function add(a: number, b: number) {
  return a + b;
}
src/utils.test.ts
import { expect, test } from '@rstest/core';
import { add } from './utils';

test('should add two numbers correctly', () => {
  expect(add(1, 2)).toBe(3);
  expect(add(-1, 1)).toBe(0);
});

#Running tests

# Run tests
npm run test

# Run and watch
npm run test:watch

These are the basic steps for using Rstest. Check the Rstest documentation for more usage details.

#Examples

Refer to the following examples for more usage patterns:

  • react-rstest: Using Rstest and React Testing Library to test React components.
  • react-jest: Using Jest and React Testing Library to test React components.

#End-to-End testing

End-to-end testing validates complete user workflows, ensuring your application functions correctly in real browser environments.

For E2E testing, we recommend Playwright, a modern end-to-end testing framework. See the Playwright documentation for details.