Class TeaVMJupiterExtension

java.lang.Object
org.teavm.junit.TeaVMJupiterExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.ExecutionCondition, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor

public final class TeaVMJupiterExtension extends Object implements org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.ExecutionCondition, org.junit.jupiter.api.extension.BeforeAllCallback
Runs @Test-annotated methods on every enabled TeaVM backend (JS, Wasm GC, C), in addition to the plain JVM.

By default, all test methods of a class are compiled together into one artifact per backend (in beforeAll(org.junit.jupiter.api.extension.ExtensionContext)), the same way TeaVMTestRunner does for JUnit 4/TestNG — compiling once per class is far cheaper than compiling once per method. Annotate the class with EachTestCompiledSeparately to opt out and compile each method on its own instead.

This only supports the subset of JUnit 5 that maps onto TeaVM's ahead-of-time compilation model: plain @Test methods, @ParameterizedTest methods, instance-level @BeforeEach/@AfterEach (recognized directly off the compiled class by TestEntryPointTransformer, the same way JUnit 4's @Before/@After already are), and TeaVM's own annotations (SkipPlatform, OnlyPlatform, SkipJVM, JsModuleTest, TeaVMProperties). There's no support for the general @ExtendWith extension mechanism, @Nested classes, dynamic tests, or @BeforeAll/@AfterAll — none of those have a sound ahead-of-time-compiled equivalent (or, in the case of other extensions, would require re-executing arbitrary reflective JVM code inside the compiled artifact).

Arguments of parameterized tests are produced inside the compiled artifact (see JupiterArgumentsPlan). All invocations run at once, within a single run of the compiled test, when Jupiter performs the first invocation on the JVM; each invocation then reports the result of the invocation with the same index (see InvocationResults). Supported argument sources are @ValueSource, @CsvSource, @EnumSource, @NullSource, @EmptySource, @NullAndEmptySource, @MethodSource and @FieldSource (with parameterless factory methods). Explicit argument converters, aggregators, @CsvFileSource and custom @ArgumentsSource providers are not supported.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T>
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    org.junit.jupiter.api.extension.ConditionEvaluationResult
    evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)
     
    void
    interceptAfterEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    void
    interceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    void
    interceptTestMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    void
    interceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    interceptAfterAllMethod, interceptBeforeAllMethod, interceptDynamicTest, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod
  • Constructor Details

    • TeaVMJupiterExtension

      public TeaVMJupiterExtension()
  • Method Details

    • evaluateExecutionCondition

      public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      evaluateExecutionCondition in interface org.junit.jupiter.api.extension.ExecutionCondition
    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • interceptTestMethod

      public void interceptTestMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable
      Specified by:
      interceptTestMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • interceptBeforeEachMethod

      public void interceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable
      Specified by:
      interceptBeforeEachMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • interceptAfterEachMethod

      public void interceptAfterEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable
      Specified by:
      interceptAfterEachMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • interceptTestTemplateMethod

      public void interceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable
      Specified by:
      interceptTestTemplateMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable