---
title: "TruffleRunner.RunWithPolyglotRule"
description: "JUnit rule to run the tests in the context of a polyglot engine."
kind: "class"
id: "com.oracle.truffle.tck.TruffleRunner$RunWithPolyglotRule"
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.RunWithPolyglotRule.html"
---

# ◆ TruffleRunner.RunWithPolyglotRule

[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.27. Nested in [`TruffleRunner`](TruffleRunner.md).

```java
public static final class TruffleRunner.RunWithPolyglotRule implements TestRule
```

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

Implements: `TestRule`

JUnit rule to run the tests in the context of a polyglot engine. This can be used as a `ClassRule` or as a `Rule`.

If used as `ClassRule`, a single context is created for all unit tests in this class, and all tests (and also other methods like `BeforeClass`, `Before` `After` and `AfterClass`) are executed in this context.

If used as `Rule`, a new context is created for each unit test. The `Before` and `After` actions are also executed in this context. No context is available in the `BeforeClass` and `AfterClass` methods.

## Constructors

### RunWithPolyglotRule()
<a id="&lt;init&gt;()"></a>`public RunWithPolyglotRule()`. Since 0.27. Cite: `com/oracle/truffle/tck/TruffleRunner.RunWithPolyglotRule.html#<init>()`

### RunWithPolyglotRule(Context.Builder)
<a id="&lt;init&gt;(org.graalvm.polyglot.Context.Builder)"></a>`public RunWithPolyglotRule(Context.Builder contextBuilder)`. Since 19.0. Parameters: `contextBuilder` `Context.Builder`: a custom context builder. Cite: `com/oracle/truffle/tck/TruffleRunner.RunWithPolyglotRule.html#<init>(org.graalvm.polyglot.Context.Builder)`

## Methods

### apply(Statement, Description)
<a id="apply(org.junit.runners.model.Statement,org.junit.runner.Description)"></a>`public Statement apply(Statement stmt, Description description)`. Since 0.27. Internal method used by the JUnit framework. Do not call directly. Overrides `apply(org.junit.runners.model.Statement,org.junit.runner.Description)`. Cite: `com/oracle/truffle/tck/TruffleRunner.RunWithPolyglotRule.html#apply(org.junit.runners.model.Statement,org.junit.runner.Description)`

### getPolyglotContext()
<a id="getPolyglotContext()"></a>`public Context getPolyglotContext()`. Since 0.27. Get the current `Context`. This should only be called from code that is executed by the `TruffleRunner`. In particular, this method can not be called from static initializers and constructors of test classes. Use `Before` or `BeforeClass` methods instead, or put the initialization code into the constructor of the [`RootNode`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/nodes/RootNode.html) of the test. Cite: `com/oracle/truffle/tck/TruffleRunner.RunWithPolyglotRule.html#getPolyglotContext()`

### getTruffleTestEnv()
<a id="getTruffleTestEnv()"></a>`public TruffleLanguage.Env getTruffleTestEnv()`. Since 0.27. Get an environment to access the polyglot engine using interop. This can be used to run setup tasks, and to do mock interop access into the polyglot engine. This should only be called from code that is executed by the `TruffleRunner`. In particular, this method can not be called from static initializers and constructors of test classes. Use `Before` or `BeforeClass` methods instead, or put the initialization code into the constructor of the [`RootNode`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/nodes/RootNode.html) of the test. Cite: `com/oracle/truffle/tck/TruffleRunner.RunWithPolyglotRule.html#getTruffleTestEnv()`

### getTestLanguage()
<a id="getTestLanguage()"></a>`public TruffleLanguage<?> getTestLanguage()`. Since 21.1. Get an instance of the [`TruffleLanguage`](https://graalvm.elide.help/25.6.0-elide.4/api/truffle-api/com/oracle/truffle/api/TruffleLanguage.html) that this test is running under. Nodes that are used with `Inject` should pass this instance to their super constructor. Cite: `com/oracle/truffle/tck/TruffleRunner.RunWithPolyglotRule.html#getTestLanguage()`

## Inherited members

- 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)
