datatest-stable icon indicating copy to clipboard operation
datatest-stable copied to clipboard

How to generate multiple tests from one file?

Open matthiasbeyer opened this issue 9 months ago • 3 comments

Hi! Awesome crate, thanks for implementing it.

I wonder how I can generate multiple tests from one input file?


I have a scenario where I have a DSLish test script, which represents a test-fixture I can throw against my application via datatest-stable. Think something like:

TestFixture:
    setup_app(name="foo")
    setup_client(name="c")
    connect_client(app="foo", name="c")
    client_send_command(name="c", command="process_data", data=[1,2,3])
    expect_client_received_reply(name="c", reply=6)

that is then run against my application as an end-to-end-test so to speak.

In reality the tests are much more complex of course, but that's all closed source, so I cannot share more here.

I am currently playing with the tera templating engine to generate multiple test-fixtures from one file:

{% for i in range(end=100) %}
TestFixture:
    setup_app(name="foo{i}")
    {% for j in range(end=100) %}
        setup_client(name="c{j}")
    {% endfor %}
    {% for j in range(end=100) %}
        connect_client(app="foo", name="c")
    {% endfor %}

...and so on, I hope you get the idea. But that would mean that I have multiple test fixtures that are generated per input file. Right now, I would run them with a single call to datatest-stable. That works.

What would be really nice though, would be to run them as individual calls to datatest-stable, so that I get (for the above example) 100 test runs, one for each fixture.


Maybe I am just "holding it wrong" and just don't see the obvious solution. But maybe not, then this is a "howto" or feature request issue 😉 .

I hope you have a great weekend!

matthiasbeyer avatar Feb 21 '25 10:02 matthiasbeyer

I have the same question. In my case I am using yaml files, each file has a list of entries, and each entry could be its own test. Maybe I'll just rewrite each file as a folder with a bunch of files...

camsteffen avatar Mar 11 '25 14:03 camsteffen

You can list out multiple tests in the macro with the same patterns. Would that work for you?

https://github.com/oxidecomputer/daft/blob/main/daft-derive/tests/snapshot_test.rs is an example that lists out two tests with different patterns, but you could also use the same patterns here.

sunshowers avatar Mar 11 '25 19:03 sunshowers

It looks like that is still "one file = one test".

camsteffen avatar Mar 12 '25 15:03 camsteffen