Class OpenTest

java.lang.Object
cloud.opencode.base.test.OpenTest

public final class OpenTest extends Object
Open Test 开放测试

Main facade for testing utilities.

测试工具的主要门面。

Features | 主要功能:

  • Testing facade for assertions, mocks, benchmarks - 断言、模拟、基准测试的测试门面
  • Record assertions and auto-fill data generation - Record断言和自动填充数据生成
  • Timing assertions and edge case generators - 性能断言和边界值生成器
  • Zero-dependency test utilities - 零依赖测试工具

Usage Examples | 使用示例:

OpenTest.assertThat("hello").isNotBlank();
OpenTest.assertThat(42).isEqualTo(42);
OpenTest.assertRecord(myRecord).hasComponent("name", "Alice");
OpenTest.assertCompletesWithin(Duration.ofMillis(100), () -> compute());
UserService mock = OpenTest.mock(UserService.class).build();
User user = OpenTest.autoFill(User.class).build();
Duration time = OpenTest.time(() -> heavyOperation());

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • assertThat

      public static <T> OpenAssertions.ObjectAssertion<T> assertThat(T actual)
    • assertThat

      public static OpenAssertions.StringAssertion assertThat(String actual)
    • assertThat

      public static <T> OpenAssertions.CollectionAssertion<T> assertThat(Collection<T> actual)
    • assertThat

      public static <K,V> OpenAssertions.MapAssertion<K,V> assertThat(Map<K,V> actual)
    • assertThat

      public static OpenAssertions.NumberAssertion assertThat(Number actual)
    • assertThat

      public static OpenAssertions.BooleanAssertion assertThat(Boolean actual)
    • assertThatThrownBy

      public static OpenAssertions.ThrowableAssertion assertThatThrownBy(Runnable runnable)
    • assertThatCode

      public static void assertThatCode(Runnable runnable)
    • mock

      public static <T> MockBuilder<T> mock(Class<T> interfaceType)
    • quickMock

      public static <T> T quickMock(Class<T> interfaceType)
    • spy

      public static Spy spy()
    • time

      public static Duration time(Runnable runnable)
    • time

      public static <T> Benchmark.TimedResult<T> time(Supplier<T> supplier)
    • benchmark

      public static Benchmark.BenchmarkResult benchmark(String name, Runnable runnable)
    • compare

      public static Benchmark.ComparisonResult compare(String name1, Runnable r1, String name2, Runnable r2)
    • randomString

      public static String randomString(int length)
    • randomEmail

      public static String randomEmail()
    • randomPhone

      public static String randomPhone()
    • randomName

      public static String randomName()
    • uuid

      public static String uuid()
    • randomInt

      public static int randomInt(int max)
    • randomInt

      public static int randomInt(int min, int max)
    • randomDouble

      public static double randomDouble()
    • randomBoolean

      public static boolean randomBoolean()
    • randomBytes

      public static byte[] randomBytes(int length)
    • oneOf

      @SafeVarargs public static <T> T oneOf(T... options)
    • assertRecord

      public static <T extends Record> RecordAssert<T> assertRecord(T record)
      Create a fluent assertion for a Record instance. 为 Record 实例创建流式断言。
      Type Parameters:
      T - the record type | Record 类型
      Parameters:
      record - the record to assert on | 要断言的 Record
      Returns:
      the record assertion | Record 断言
    • assertMap

      public static <K,V> MapAssert<K,V> assertMap(Map<K,V> map)
      Create a fluent assertion for a Map. 为 Map 创建流式断言。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      map - the map to assert on | 要断言的 Map
      Returns:
      the map assertion | Map 断言
    • assertCompletesWithin

      public static void assertCompletesWithin(Duration timeout, Runnable task)
      Assert that a task completes within the given duration. 断言任务在指定时间内完成。
      Parameters:
      timeout - the maximum duration | 最大时长
      task - the task to run | 要运行的任务
    • assertCompletesWithin

      public static <T> T assertCompletesWithin(Duration timeout, Callable<T> task)
      Assert that a callable completes within the given duration and return its result. 断言 Callable 在指定时间内完成并返回结果。
      Type Parameters:
      T - the return type | 返回类型
      Parameters:
      timeout - the maximum duration | 最大时长
      task - the callable to run | 要运行的 Callable
      Returns:
      the result | 结果
    • autoFill

      public static <T> AutoFill.Builder<T> autoFill(Class<T> type)
      Create an auto-fill builder for the given type. 为指定类型创建自动填充构建器。
      Type Parameters:
      T - the type | 类型
      Parameters:
      type - the class to auto-fill | 要自动填充的类
      Returns:
      the builder | 构建器
    • edgeCasesForInt

      public static List<Integer> edgeCasesForInt()
      Get edge case values for int. 获取 int 类型的边界值。
      Returns:
      edge case values | 边界值列表
    • edgeCasesForString

      public static List<String> edgeCasesForString()
      Get edge case values for String. 获取 String 类型的边界值。
      Returns:
      edge case values (including null) | 边界值列表(包含 null)