---
title: "TruffleRunner"
description: "JUnit test runner for unit testing Truffle AST interpreters."
kind: "class"
id: "com.oracle.truffle.tck.TruffleRunner"
module: "truffle-tck"
version: "25.6.0-elide.4"
canonical: "https://graalvm.elide.help/25.6.0-elide.4/api/truffle-tck/com/oracle/truffle/tck/TruffleRunner.html"
---

# ◆ TruffleRunner

[truffle-tck](../../../../index.md) › [com.oracle.truffle.tck](index.md) · Every page: [llms.txt](../../../../llms.txt)

Class in [`com.oracle.truffle.tck`](index.md). Since 0.25.

```java
public class TruffleRunner extends BlockJUnit4ClassRunner
```

Inheritance: [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html) > `Runner` > `ParentRunner` > `BlockJUnit4ClassRunner` > `TruffleRunner`

JUnit test runner for unit testing Truffle AST interpreters.

A test using [`TruffleRunner`](TruffleRunner.md) consists of 2 parts, a Truffle AST to be tested, and a test method that drives the test, provides input argument values and validates the result.

#### Writing a test AST

The Truffle AST to be tested is written as a [`RootNode`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/nodes/RootNode.html) subclass, for example:

```java
public class TestExecuteNode extends RootNode {

    @Child InteropLibrary interop;

    public TestExecuteNode() {
        super(runWithPolyglot.getTestLanguage());
        interop = InteropLibrary.getFactory().createDispatched(5);
    }

    @Override
    public Object execute(VirtualFrame frame) {
        Object obj = frame.getArguments()[0];
        try {
            return interop.execute(obj);
        } catch (InteropException ex) {
            CompilerDirectives.transferToInterpreter();
            Assert.fail(ex.getMessage());
            return null;
        }
    }
}
```

#### Writing a test method

The test method is a normal method annotated with `Test`. It may have one or more arguments of type [`CallTarget`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/CallTarget.html) that are annotated with [`Inject`](TruffleRunner.Inject.md). The [`Inject`](TruffleRunner.Inject.md) annotation specifies a [`RootNode`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/nodes/RootNode.html) subclass that is the root of a test AST, and the [`TruffleRunner`](TruffleRunner.md) will create one [`CallTarget`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/CallTarget.html) for each of these test ASTs. The test method can then execute the AST by calling the [`CallTarget.call`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/CallTarget.html#call%28java.lang.Object...%29) method.

Typically a test method will prepare some arguments, and then do a single call to [`CallTarget.call`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/CallTarget.html#call%28java.lang.Object...%29). Then it should verify the result by inspecting the return value and checking the expected side effects of the test code.

```java
@RunWith(TruffleRunner.class)
public class ExampleTest {

    @Test
    public void executeTest(@Inject(TestExecuteNode.class) CallTarget target) {
        TruffleObject receiver = prepareArgumentValue();
        Object ret = target.call(receiver);
        Assert.assertEquals(expectedRetValue(), ret);
    }
}
```

#### Running a test in the polyglot engine

If a test should be run in the context of a polyglot engine, [`RunWithPolyglotRule`](TruffleRunner.RunWithPolyglotRule.md) can be used.

```java
@RunWith(TruffleRunner.class)
public static class PolyglotTest {

    @ClassRule RunWithPolyglotRule runWithPolyglot = new RunWithPolyglotRule();

    private static Object prepared;

    @BeforeClass
    public void prepare() {
        prepared = runWithPolyglot.getTruffleTestEnv().importSymbol("...");
    }

    @Test
    public void executeTest(@Inject(TestExecuteNode.class) CallTarget target) {
        Object ret = target.call(prepared);
        Assert.assertEquals(expectedRetValue(), ret);
    }
}
```

**See also**

- [`warmup iterations and compilation`](TruffleRunner.Warmup.md)
- [`parameterized Truffle AST tests`](TruffleRunner.ParametersFactory.md)

## Nested types

- [`TruffleRunner.Inject`](TruffleRunner.Inject.md) (annotation interface): A parameter annotated with Inject specifies the RootNode of the test AST.
- [`TruffleRunner.ParametersFactory`](TruffleRunner.ParametersFactory.md) (class): ParametersRunnerFactory for testing Truffle AST interpreters using Parameterized unit tests.
- [`TruffleRunner.RunWithPolyglotRule`](TruffleRunner.RunWithPolyglotRule.md) (class): JUnit rule to run the tests in the context of a polyglot engine.
- [`TruffleRunner.Warmup`](TruffleRunner.Warmup.md) (annotation interface): A test method can be annotated with Warmup to specify how many warmup iterations of a test should be done before the Truffle tree is compiled.

## Constructors

### TruffleRunner(Class)
<a id="&lt;init&gt;(java.lang.Class)"></a>`public TruffleRunner(Class<?> klass) throws InitializationError`. Since 0.25. Should not be called directly. To use this class, annotate your test class with `@RunWith(TruffleRunner.class)`. See also: `TruffleRunner`. Cite: `com/oracle/truffle/tck/TruffleRunner.html#<init>(java.lang.Class)`

### TruffleRunner(TestClass)
<a id="&lt;init&gt;(org.junit.runners.model.TestClass)"></a>`public TruffleRunner(TestClass testClass) throws InitializationError`. Since 24.2. Should not be called directly. To use this class, annotate your test class with `@RunWith(TruffleRunner.class)`. See also: `TruffleRunner`. Cite: `com/oracle/truffle/tck/TruffleRunner.html#<init>(org.junit.runners.model.TestClass)`

## Methods

### methodInvoker(FrameworkMethod, Object)
<a id="methodInvoker(org.junit.runners.model.FrameworkMethod,java.lang.Object)"></a>`protected final Statement methodInvoker(FrameworkMethod method, Object test)`. Since 0.25. Internal method used by the JUnit framework. Do not call directly. Overrides `methodInvoker(org.junit.runners.model.FrameworkMethod,java.lang.Object)`. Cite: `com/oracle/truffle/tck/TruffleRunner.html#methodInvoker(org.junit.runners.model.FrameworkMethod,java.lang.Object)`

### validateTestMethods(List)
<a id="validateTestMethods(java.util.List)"></a>`protected final void validateTestMethods(List<Throwable> errors)`. Since 0.25. Internal method used by the JUnit framework. Do not call directly. Overrides `validateTestMethods(java.util.List)`. Cite: `com/oracle/truffle/tck/TruffleRunner.html#validateTestMethods(java.util.List)`

## Inherited members

- From class `BlockJUnit4ClassRunner`: `collectInitializationErrors`, `computeTestMethods`, `createTest`, `createTest`, `describeChild`, `getChildren`, `getTestRules`, `isIgnored`, `methodBlock`, `possiblyExpectingExceptions`, `rules`, `runChild`, `testName`, `validateConstructor`, `validateFields`, `validateInstanceMethods`, `validateNoNonStaticInnerClass`, `validateOnlyOneConstructor`, `validateZeroArgConstructor`, `withAfters`, `withBefores`, `withPotentialTimeout`
- From class `ParentRunner`: `childrenInvoker`, `classBlock`, `classRules`, `createTestClass`, `filter`, `getDescription`, `getName`, `getRunnerAnnotations`, `getTestClass`, `order`, `run`, `runLeaf`, `setScheduler`, `sort`, `validatePublicVoidNoArgMethods`, `withAfterClasses`, `withBeforeClasses`, `withInterruptIsolation`
- From class `Runner`: `testCount`
- From class [`Object`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html): [`clone`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#clone%28%29), [`equals`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#equals%28java.lang.Object%29), [`finalize`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#finalize%28%29), [`getClass`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#getClass%28%29), [`hashCode`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#hashCode%28%29), [`notify`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notify%28%29), [`notifyAll`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#notifyAll%28%29), [`toString`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#toString%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long%29), [`wait`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Object.html#wait%28long,int%29)
