gpui-test by longbridge/gpui-component
npx skills add https://github.com/longbridge/gpui-component --skill gpui-testGPUI 提供了一套全面的测试框架,允许您测试 UI 组件、异步操作和分布式系统。测试在单线程执行器上运行,该执行器提供确定性执行,并能够测试复杂的异步场景。GPUI 测试使用 #[gpui::test] 属性,并与 TestAppContext(用于基础测试)和 VisualTestContext(用于依赖窗口的测试)配合工作。
[gpui::test] 和 TestAppContext,只需编写简单的 Rust 测试。#[gpui::test]
fn my_test(cx: &mut TestAppContext) {
// 测试实现
}
#[gpui::test]
async fn my_async_test(cx: &mut TestAppContext) {
// 异步测试实现
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
#[gpui::test(iterations = 10)]
fn my_property_test(cx: &mut TestAppContext, mut rng: StdRng) {
// 使用随机数据进行属性测试
}
TestAppContext 提供对 GPUI 核心功能的访问,无需窗口:
#[gpui::test]
fn test_entity_operations(cx: &mut TestAppContext) {
// 创建实体
let entity = cx.new(|cx| MyComponent::new(cx));
// 更新实体
entity.update(cx, |component, cx| {
component.value = 42;
cx.notify();
});
// 读取实体
let value = entity.read_with(cx, |component, _| component.value);
assert_eq!(value, 42);
}
VisualTestContext 扩展了 TestAppContext,增加了窗口支持:
#[gpui::test]
fn test_with_window(cx: &mut TestAppContext) {
// 创建包含组件的窗口
let window = cx.update(|cx| {
cx.open_window(Default::default(), |_, cx| {
cx.new(|cx| MyComponent::new(cx))
}).unwrap()
});
// 转换为可视化上下文
let mut cx = VisualTestContext::from_window(window.into(), cx);
// 访问窗口和组件
let component = window.root(&mut cx).unwrap();
}
每周安装量
132
代码仓库
GitHub 星标数
10.8K
首次出现
2026年1月21日
安全审计
安装于
opencode123
gemini-cli116
codex116
github-copilot109
cursor107
claude-code101
GPUI provides a comprehensive testing framework that allows you to test UI components, async operations, and distributed systems. Tests run on a single-threaded executor that provides deterministic execution and the ability to test complex async scenarios. GPUI tests use the #[gpui::test] attribute and work with TestAppContext for basic testing and VisualTestContext for window-dependent tests.
[gpui::test] and TestAppContext, just write simple rust test.#[gpui::test]
fn my_test(cx: &mut TestAppContext) {
// Test implementation
}
#[gpui::test]
async fn my_async_test(cx: &mut TestAppContext) {
// Async test implementation
}
#[gpui::test(iterations = 10)]
fn my_property_test(cx: &mut TestAppContext, mut rng: StdRng) {
// Property testing with random data
}
TestAppContext provides access to GPUI's core functionality without windows:
#[gpui::test]
fn test_entity_operations(cx: &mut TestAppContext) {
// Create entities
let entity = cx.new(|cx| MyComponent::new(cx));
// Update entities
entity.update(cx, |component, cx| {
component.value = 42;
cx.notify();
});
// Read entities
let value = entity.read_with(cx, |component, _| component.value);
assert_eq!(value, 42);
}
VisualTestContext extends TestAppContext with window support:
#[gpui::test]
fn test_with_window(cx: &mut TestAppContext) {
// Create window with component
let window = cx.update(|cx| {
cx.open_window(Default::default(), |_, cx| {
cx.new(|cx| MyComponent::new(cx))
}).unwrap()
});
// Convert to visual context
let mut cx = VisualTestContext::from_window(window.into(), cx);
// Access window and component
let component = window.root(&mut cx).unwrap();
}
Weekly Installs
132
Repository
GitHub Stars
10.8K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode123
gemini-cli116
codex116
github-copilot109
cursor107
claude-code101
UI组件模式实战指南:构建可复用React组件库与设计系统
10,700 周安装
Webhook集成指南:实现实时通信与第三方服务集成的最佳实践
131 周安装
AXe iOS 模拟器 UI 自动化 CLI 工具:基于辅助功能 API 的稳定测试
131 周安装
iOS Core Data 完整指南:与 SwiftData 对比、现代堆栈设置与迁移策略
131 周安装
iOS深度链接调试指南:SwiftUI自动化测试与截图解决方案
131 周安装
iOS SwiftUI/UIKit 照片库访问指南:PhotoKit、PhotosPicker、PHPicker 隐私保护开发
131 周安装
iOS隐私设计指南:创建隐私清单、ATT实施与用户体验优化
131 周安装