Skip to main content
Version: 1.0.10

๐Ÿงช Testing Core Primitives

ElizaOS encourages thorough testing of providers, actions and evaluators. Component tests use Vitest, while scenario tests run through the ElizaOS runtime.

Component Testsโ€‹

For unit style tests, import helpers from the bootstrap plugin test utilities and call the primitive directly.

import { describe, it, expect } from 'vitest';
import { timeProvider } from '@elizaos/plugin-bootstrap';
import {
createMockRuntime,
createMockMemory,
} from '@elizaos/plugin-bootstrap/__tests__/test-utils';

describe('time provider', () => {
it('returns a time string', async () => {
const runtime = createMockRuntime();
const msg = createMockMemory();
const result = await timeProvider.get(runtime as any, msg as any);
expect(result.values.time).toBeDefined();
});
});

End-to-End Testsโ€‹

Scenario tests use a TestSuite loaded by the CLI test command. Each test receives a running IAgentRuntime instance.

import type { TestSuite } from '@elizaos/core';
import { bootstrapPlugin } from '@elizaos/plugin-bootstrap';

export class BootstrapSuite implements TestSuite {
name = 'bootstrap_example';
tests = [
{
name: 'reply action works',
fn: async (runtime) => {
const action = runtime.actions.find((a) => a.name === 'REPLY');
if (!action) throw new Error('action missing');
await action.handler(
runtime,
{ content: { text: 'hi' } } as any,
{ values: {} } as any,
{},
() => {}
);
},
},
];
}
export default new BootstrapSuite();

Run all tests with:

elizaos test

Component and e2e tests can be filtered using --name and built beforehand with bun run build.