You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project's test source files I was spending more and more time switching between a normal cucumber output and an output allowing me to debug my tests (with tracing integration 💟 ). Since I don't like to allow unused imports I was often spending time adjusting, commenting, or uncommenting multiple use statements in addition to commenting and uncommenting big chunks of my cucumber's call in async fn main() {World::cucumber...}. And I had to do this across multiple test source files and keep the imports and calling code mutually in sync.
Now I think I have a solution where all it takes to switch between debug and normal output is to rewrite a single word in the code of a test source file. It goes like this:
This is my test helper crate test_utils.rs which defines the common things across my tests. It contains, among other things, this code:
// test_utils/src/lib.rsuse cucumber::{parser, runner, writer,Cucumber,Worldas _,WriterExt};use futures::FutureExtas _;use std::{io, path::Path};use tracing_subscriber::{
filter,
fmt::format,
layer::{Layer,SubscriberExtas _},};// my own World for the tests#[derive(Debug, cucumber::World)]#[world(init = Self::new)]pubstructWorld{/* ... */}implWorld{fnnew() -> Self{Self{/* ... */}}}// Cucumber with normal outputpubfnnormal_world<I:AsRef<Path>>() -> cucumber::Cucumber<World,
parser::Basic,I,
runner::Basic<World>,
writer::Summarize<writer::Normalize<World, writer::Basic>>,>{World::cucumber()// add other settings here which you consider normal}// Cucumber with debugging outputpubfndebug_world<I:AsRef<Path>>() -> Cucumber<World,
parser::Basic,I,
runner::Basic<World>,
writer::AssertNormalized<writer::Summarize<writer::Basic>>,>{World::cucumber()// add your debugging settings here,// e.g. this tracing integration.max_concurrent_scenarios(1).with_writer(
writer::Basic::raw(io::stdout(), writer::Coloring::Never,0).summarized().assert_normalized(),).configure_and_init_tracing(
format::DefaultFields::new(),
format::Format::default(),
|layer| {
tracing_subscriber::registry().with(filter::LevelFilter::TRACE.and_then(layer))},)}
Most crucially, test_utils defines the debug_world and the normal_world functions. I import them in my test source code like this
// project/tests/some_feature.rsuse test_utils::{debug_world as construct_world,World};/* * implement some steps here */#[tokio::main]asyncfnmain(){let world = construct_world();
world.run("tests/features/some_feature.feature").await;}
So now I can just change between normal and debug output by replacing the in debug_world as construct_world with normal_world as construct world. A lot of the import clutter is kept hidden in the test_utils crate.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In my project's test source files I was spending more and more time switching between a normal cucumber output and an output allowing me to debug my tests (with tracing integration 💟 ). Since I don't like to allow unused imports I was often spending time adjusting, commenting, or uncommenting multiple
use
statements in addition to commenting and uncommenting big chunks of my cucumber's call inasync fn main() {World::cucumber...}
. And I had to do this across multiple test source files and keep the imports and calling code mutually in sync.Now I think I have a solution where all it takes to switch between debug and normal output is to rewrite a single word in the code of a test source file. It goes like this:
This is my test helper crate test_utils.rs which defines the common things across my tests. It contains, among other things, this code:
Most crucially, test_utils defines the
debug_world
and thenormal_world
functions. I import them in my test source code like thisSo now I can just change between normal and debug output by replacing the in
debug_world as construct_world
withnormal_world as construct world
. A lot of the import clutter is kept hidden in the test_utils crate.Beta Was this translation helpful? Give feedback.
All reactions