Class OpenTest
java.lang.Object
cloud.opencode.base.test.OpenTest
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 Summary
Modifier and TypeMethodDescriptionstatic voidassertCompletesWithin(Duration timeout, Runnable task) Assert that a task completes within the given duration.static <T> TassertCompletesWithin(Duration timeout, Callable<T> task) Assert that a callable completes within the given duration and return its result.static <K,V> MapAssert <K, V> Create a fluent assertion for a Map.static <T extends Record>
RecordAssert<T> assertRecord(T record) Create a fluent assertion for a Record instance.assertThat(Boolean actual) assertThat(Number actual) assertThat(String actual) static <T> OpenAssertions.CollectionAssertion<T> assertThat(Collection<T> actual) static <K,V> OpenAssertions.MapAssertion <K, V> assertThat(Map<K, V> actual) static <T> OpenAssertions.ObjectAssertion<T> assertThat(T actual) static voidassertThatCode(Runnable runnable) assertThatThrownBy(Runnable runnable) static <T> AutoFill.Builder<T> Create an auto-fill builder for the given type.static Benchmark.BenchmarkResultstatic Benchmark.ComparisonResultGet edge case values for int.Get edge case values for String.static <T> MockBuilder<T> static <T> ToneOf(T... options) static <T> Tstatic booleanstatic byte[]randomBytes(int length) static doublestatic Stringstatic intrandomInt(int max) static intrandomInt(int min, int max) static Stringstatic Stringstatic StringrandomString(int length) static Spyspy()static Durationstatic <T> Benchmark.TimedResult<T> static Stringuuid()
-
Method Details
-
assertThat
-
assertThat
-
assertThat
-
assertThat
-
assertThat
-
assertThat
-
assertThatThrownBy
-
assertThatCode
-
mock
-
quickMock
-
spy
-
time
-
time
-
benchmark
-
compare
public static Benchmark.ComparisonResult compare(String name1, Runnable r1, String name2, Runnable r2) -
randomString
-
randomEmail
-
randomPhone
-
randomName
-
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
-
assertRecord
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
-
assertCompletesWithin
-
assertCompletesWithin
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
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
-
edgeCasesForString
-