Class TestFixture<T>

java.lang.Object
cloud.opencode.base.test.fixture.TestFixture<T>
Type Parameters:
T - the fixture data type | 夹具数据类型

public class TestFixture<T> extends Object
Test Fixture 测试夹具

A reusable test fixture that can be set up and torn down.

可重用的测试夹具,可以设置和拆除。

Features | 主要功能:

  • Reusable test data fixtures - 可重用的测试数据夹具
  • Setup and teardown lifecycle - 设置和拆卸生命周期

Usage Examples | 使用示例:

TestFixture<User> fixture = TestFixture.of(() -> new User("test"));
User user = fixture.get();

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • TestFixture

      public TestFixture(String name, Supplier<T> setup)
      Create test fixture 创建测试夹具
      Parameters:
      name - the fixture name | 夹具名称
      setup - the setup function | 设置函数
    • TestFixture

      public TestFixture(String name, Supplier<T> setup, Consumer<T> teardown)
      Create test fixture with teardown 创建带拆除的测试夹具
      Parameters:
      name - the fixture name | 夹具名称
      setup - the setup function | 设置函数
      teardown - the teardown function | 拆除函数
  • Method Details

    • builder

      public static <T> TestFixture.Builder<T> builder(String name)
      Create fixture builder 创建夹具构建器
      Type Parameters:
      T - the data type | 数据类型
      Parameters:
      name - the fixture name | 夹具名称
      Returns:
      the builder | 构建器
    • getName

      public String getName()
      Get fixture name 获取夹具名称
      Returns:
      the name | 名称
    • setUp

      public T setUp()
      Set up the fixture 设置夹具
      Returns:
      the fixture data | 夹具数据
    • get

      public T get()
      Get the fixture data (alias for setUp) 获取夹具数据(setUp的别名)
      Returns:
      the fixture data | 夹具数据
    • tearDown

      public void tearDown()
      Tear down the fixture 拆除夹具
    • isInitialized

      public boolean isInitialized()
      Check if initialized 检查是否已初始化
      Returns:
      true if initialized | 如果已初始化返回true
    • reset

      public void reset()
      Reset the fixture 重置夹具