Skip to content
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

Named tests #160

Closed
infiniteregrets opened this issue Aug 3, 2022 · 7 comments
Closed

Named tests #160

infiniteregrets opened this issue Aug 3, 2022 · 7 comments

Comments

@infiniteregrets
Copy link

My test has a signature like so:

async fn test_mirror_http_traffic(
        #[future]
        service: EchoService,
        #[future]
        kube_client: Client,
        #[values(Application::PythonHTTP, Application::NodeHTTP, Application::GoHTTP)] application: Application,
        #[values(Agent::Ephemeral, Agent::Job)] agent: Agent,
    )

And when the tests are run, on failure/success I get output like this

failures:
    tests::test_mirror_http_traffic::application_1::agent_1
    tests::test_mirror_http_traffic::application_2::agent_1
    tests::test_mirror_http_traffic::application_2::agent_2

It is very hard to know which application/agent failed, so is there a way to have the name of the tests similar to the name of the variants when using #[values]?
Defining cases explicitly can be a mess, and I don't want to do #[case::go_job(App::GO, Agent::Job)] or use #[trace]/#[notrace]

Thanks!

@la10736
Copy link
Owner

la10736 commented Oct 23, 2022

Ok,
the issue here is that the values are just expressions at compile time: We cannot know what value we can have at runtime.

What we can do is simply add a sanitized string from the expression by just take valid characters and discard the others. Maybe some chars can be replaced by _ (i.e. :) instead just discarding.

@infiniteregrets
Copy link
Author

Ok, the issue here is that the values are just expressions at compile time: We cannot know what value we can have at runtime.

What we can do is simply add a sanitized string from the expression by just take valid characters and discard the others. Maybe some chars can be replaced by _ (i.e. :) instead just discarding.

Thanks for checking this! and this sounds good

@la10736
Copy link
Owner

la10736 commented Nov 6, 2022

I'll limit the rendered part to 64 chars.... It should be enough.

@TomPridham
Copy link

it would also be nice to be able to specify a string name for parameterized tests as well, similar to: https://docs.rs/test-case/latest/test_case/#example-usage

@la10736
Copy link
Owner

la10736 commented Nov 12, 2022

You can already do it for cases... not for values.

https://docs.rs/rstest/latest/rstest/attr.rstest.html#optional-case-description

For values doesn't have too much sense IMHO

@la10736
Copy link
Owner

la10736 commented Nov 13, 2022

@TomPridham Same example in rstest:

#[rstest]
#[case::when_both_operands_are_negative(-2, -4]
#[case::when_both_operands_are_positive(2,  4)]
#[case::when_operands_are_swapped(4,  2)]
fn multiplication_tests(x: i8, y: i8) {
    let actual = (x * y).abs();
    assert_eq!(8, actual)
}

Output should be something like

test multiplication_tests::case_1_when_both_operands_are_negative ... ok
test multiplication_tests::case_2_when_both_operands_are_positive ... ok
test multiplication_tests::case_3_when_operands_are_swapped ... ok

You can find the motivation of why I choose to leave the case_<nr> also when description is present in #167

la10736 added a commit that referenced this issue Nov 20, 2022
* WIP: enable check tests by partial name

* WIP: values tests name from content

* WIP: Single test check itself

* Now framework accept also contains rule

* Add ok_in and fail_in shortcut

* Fixed tests and operation characters traslated to _
la10736 added a commit that referenced this issue Nov 20, 2022
la10736 added a commit that referenced this issue Nov 27, 2022
la10736 added a commit that referenced this issue Nov 27, 2022
la10736 added a commit that referenced this issue Nov 27, 2022
la10736 added a commit that referenced this issue Nov 27, 2022
@la10736
Copy link
Owner

la10736 commented Nov 27, 2022

Released

@la10736 la10736 closed this as completed Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants