Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
Commands Reference

aigne test


Ensuring your Agent behaves as expected is crucial. The aigne test command provides a straightforward way to run tests for your AIGNE project. It leverages the built-in Node.js test runner, so you can write tests using familiar tools and conventions without any extra setup.

This command simplifies the testing process by automatically locating your project and running the tests within the correct context.

How It Works#

The aigne test command acts as a convenient wrapper around the native Node.js test runner (node --test). When you execute it, the CLI performs the following steps:

User runs 'aigne test'

Find project root (location of aigne.yaml)

Execute 'node --test' in the root directory

Node.js discovers and runs test files (e.g., *.test.js)

Test results are displayed in the console


This means any file in your project that follows the Node.js test file conventions (such as *.test.js, *.spec.js, or test-*.js) will be automatically discovered and executed.

Usage#

To run tests in the current project directory, simply execute the command:

# Test the Agent in the current directory
aigne test

If your project is located elsewhere, you can specify the path:

# Test the Agent at a specific path
aigne test --path path/to/agents

Options#

The test command accepts the following options to customize its behavior:

Option

Alias

Description

Default

--path <path_or_url>

--url

The local path or remote URL to your AIGNE project directory.

. (the current directory)

Example: Writing and Running a Test#

The default AIGNE project template includes a sample test file to get you started. This demonstrates how to test a JavaScript module within your project.

1. The Test File#

Here is the content of sandbox.test.js from the default template. It uses the built-in node:test and node:assert modules to verify the functionality of a sandbox.js file.

// sandbox.test.js
import assert from "node:assert";
import test from "node:test";
import evaluateJs from "./sandbox.js";

test("evaluateJs should execute script correctly", async () => {
assert.deepEqual(await evaluateJs({ code: "1 + 2" }), { result: 3 });
});

This test defines a simple case: it checks that the evaluateJs function correctly computes 1 + 2 and returns the result 3.

2. Running the Test#

With the test file in place, you can run it using the aigne test command. The CLI will find and execute it, and you'll see the output directly in your terminal.

aigne test

The output will be from the Node.js test runner, indicating whether the tests passed or failed.


Testing is an integral part of building reliable AI applications. With aigne test, you have a simple yet effective tool integrated directly into your workflow. After verifying your Agent's logic, the next step is often to make it available to other services.

Learn how to do this with the aigne serve-mcp command. Next: Expose Your Agent with aigne serve-mcp