Skip to content

Installation

Prerequisites

  • Node.js 18.0.0 or higher
  • npm, pnpm, or yarn package manager

Install the Core Package

The core testurio package includes the framework essentials and the built-in HTTP protocol:

bash
npm install testurio
bash
pnpm add testurio
bash
yarn add testurio

Protocol Packages

Install additional protocol packages based on the protocols you need to test:

PackageProtocolInstall
testurioHTTPIncluded in core
@testurio/protocol-grpcgRPC (Unary & Streaming)npm install @testurio/protocol-grpc
@testurio/protocol-wsWebSocketnpm install @testurio/protocol-ws
@testurio/protocol-tcpTCPnpm install @testurio/protocol-tcp

Adapter Packages

For message queues and data sources, install the corresponding adapter packages:

Message Queues

PackageServiceInstall
@testurio/adapter-kafkaApache Kafkanpm install @testurio/adapter-kafka
@testurio/adapter-rabbitmqRabbitMQnpm install @testurio/adapter-rabbitmq
@testurio/adapter-redisRedis Pub/Subnpm install @testurio/adapter-redis

Data Sources

PackageServicePeer DependencyInstall
@testurio/adapter-redisRedisioredisnpm install @testurio/adapter-redis ioredis
@testurio/adapter-pgPostgreSQLpgnpm install @testurio/adapter-pg pg
@testurio/adapter-mongoMongoDBmongodbnpm install @testurio/adapter-mongo mongodb

CLI (Schema Generator)

The CLI generates type-safe Zod schemas and service interfaces from OpenAPI specs and .proto files:

bash
npm install @testurio/cli --save-dev

Reporter

For Allure HTML test reports:

bash
npm install @testurio/reporter-allure

Test Runner

Testurio is test-runner agnostic. You can use it with any test runner, but it works especially well with Vitest:

bash
npm install vitest --save-dev

Example with Vitest:

typescript
import { describe, it, expect } from 'vitest';
import { TestScenario, testCase, Client, Server, HttpProtocol } from 'testurio';

describe('User API', () => {
  const client = new Client('api', {
    protocol: new HttpProtocol(),
    targetAddress: { host: 'localhost', port: 3000 },
  });

  const server = new Server('mock', {
    protocol: new HttpProtocol(),
    listenAddress: { host: 'localhost', port: 3000 },
  });

  const scenario = new TestScenario({
    name: 'User API',
    components: [server, client],
  });

  it('should return users', async () => {
    const tc = testCase('get users', (test) => {
      const api = test.use(client);
      const mock = test.use(server);

      api.request('getUsers', { method: 'GET', path: '/users' });
      mock.onRequest('getUsers').mockResponse(() => ({
        code: 200,
        body: [{ id: 1, name: 'Alice' }],
      }));
      api.onResponse('getUsers').assert((res) => res.body.length === 1);
    });

    const result = await scenario.run(tc);
    expect(result.passed, result.error).toBe(true);
  });
});

Next Steps

Released under the MIT License.