-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add egui_kittest
, a test harness for egui
#5166
Conversation
Preview available at https://egui-pr-preview.github.io/pr/5166-lucas/testing_library |
After some discussion we came to these conclusions:
|
9b76b0b
to
a0a9671
Compare
4ac8fea
to
d167452
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so awesome!
The PR description is a bit outdated though
@@ -1,2 +1,3 @@ | |||
* text=auto eol=lf | |||
Cargo.lock linguist-generated=false | |||
**/tests/snapshots/**/*.png filter=lfs diff=lfs merge=lfs -text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just apply lfs to all png:s everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, but I think we should do that in a separate PR. And it should also include gifs, which seem to be the biggest files in the repo. And maybe also the entirety of the media folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's something wrong with the framing on this one!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's because this one has constrain(false)
. No idea how I could fix that though without changing constrain to true 🤔
crates/egui_kittest/src/snapshot.rs
Outdated
}); | ||
} | ||
|
||
let result = dify::diff::get_results(previous, current.clone(), 0.1, true, None, &None, &None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And separately - have you tested tolerance=0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to 0, but I think we should at least have someone test this on linux and windows. I can test on windows but someone else will need to test it for linux. Preferably once with the vulkan and once with the gl backend.
88324d1
to
27414ea
Compare
I've changed everything you mentioned and also added Also, I've disabled dithering since it caused minor differences between frames. This made the pngs much smaller! |
egui_kittest
, a test harness for egui
The check.sh script was broken in #5166, this fixes it * Related to #5297 * [x] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
The check.sh script was broken in #5166, this fixes it * Related to #5297 * [x] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
The check.sh script was broken in #5166, this fixes it * Related to #5297 * [x] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
- closes emilk#3491 - closes emilk#3926 This adds a testing library to egui based on [kittest](https://github.com/rerun-io/kittest). Kittest is a new [AccessKit](https://github.com/AccessKit/accesskit/)-based testing library. The api is inspired by the js [testing-library](https://testing-library.com/) where the idea is also to query the dom based on accessibility attributes. We made kittest with egui in mind but it should work with any rust gui framework with AccessKit support. It currently has support for: - running the egui app, frame by frame - building the AccessKit tree - ergonomic queries via kittest - via e.g. get_by_name, get_by_role - simulating events based on the accesskit node id - creating arbitrary events based on Harness::input_mut - rendering screenshots via wgpu - snapshot tests with these screenshots A simple test looks like this: ```rust fn main() { let mut checked = false; let app = |ctx: &Context| { CentralPanel::default().show(ctx, |ui| { ui.checkbox(&mut checked, "Check me!"); }); }; let mut harness = Harness::builder().with_size(egui::Vec2::new(200.0, 100.0)).build(app); let checkbox = harness.get_by_name("Check me!"); assert_eq!(checkbox.toggled(), Some(Toggled::False)); checkbox.click(); harness.run(); let checkbox = harness.get_by_name("Check me!"); assert_eq!(checkbox.toggled(), Some(Toggled::True)); // You can even render the ui and do image snapshot tests #[cfg(all(feature = "wgpu", feature = "snapshot"))] egui_kittest::image_snapshot(&egui_kittest::wgpu::TestRenderer::new().render(&harness), "readme_example"); } ``` ~Since getting wgpu to run in ci is a hassle, I'm taking another shot at creating a software renderer for egui (ideally without a huge dependency like skia)~ (this didn't work as well as I hoped and it turns out in CI you can just run tests on a mac runner which comes with a real GPU) Here is a example of a failed snapshot test in ci, it will say which snapshot failed and upload an artifact with the before / after and diff images: https://github.com/emilk/egui/actions/runs/11183049487/job/31090724606?pr=5166
The check.sh script was broken in emilk#5166, this fixes it * Related to emilk#5297 * [x] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
This adds a testing library to egui based on kittest. Kittest is a new AccessKit-based testing library. The api is inspired by the js testing-library where the idea is also to query the dom based on accessibility attributes.
We made kittest with egui in mind but it should work with any rust gui framework with AccessKit support.
It currently has support for:
A simple test looks like this:
Since getting wgpu to run in ci is a hassle, I'm taking another shot at creating a software renderer for egui (ideally without a huge dependency like skia)(this didn't work as well as I hoped and it turns out in CI you can just run tests on a mac runner which comes with a real GPU)Here is a example of a failed snapshot test in ci, it will say which snapshot failed and upload an artifact with the before / after and diff images:
https://github.com/emilk/egui/actions/runs/11183049487/job/31090724606?pr=5166