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

@Shared resources with parameters #808

Open
Michael1993 opened this issue Mar 30, 2024 · 2 comments
Open

@Shared resources with parameters #808

Michael1993 opened this issue Mar 30, 2024 · 2 comments

Comments

@Michael1993
Copy link
Member

I think this should be a relatively simple addition. Currently, our documentation says:

We do not support creating shared resources with arguments.
This is because if a test refers to a shared resource with the name "Foo" without arguments, then later another test refers to it with one argument, there is no reasonable way to fulfill that request.
Furthermore, even if this was supported, the behavior would change if the first and second tests ever ran in opposite order, which is very likely when tests are configured to run in parallel.

But I think we can support it with something like this:

@Shared(factory = FooResourceFactory.class, name = "sharedFoo1", parameters = { "p1", "p2" })
@Shared(factory = FooResourceFactory.class, name = "sharedFoo2", parameters = { "p3", "p4" })
class FooTests {

    @Test
    void test1(@Shared.Named("sharedFoo1") Foo foo) {
        // test here...
    }

    @Test
    void test2(@Shared.Named("sharedFoo1") Foo foo) {
        // test here...
    }

    @Test
    void test3(@Shared.Named("sharedFoo2") Foo foo) {
        // test here...
    }

    @Test
    void test4(@Shared.Named("sharedFoo2") Foo foo) {
        // test here...
    }

}

We would create the resource before the tests and then just take it from the class-scoped ExtensionContext.Store.
This does not solve (of course) how to share resources with parameters that have Scope.GLOBAL.

@Bukama
Copy link
Member

Bukama commented Mar 31, 2024

I'm a bit confused by the example/idea: Do the classes of the @Shared resources be the same or can be different. I guess they can be whatever they want?

@Michael1993
Copy link
Member Author

Yeah, if they have different names and/or factory classes, they can be whatever.

@Michael1993 Michael1993 added ⚙️ component: Pioneer Issues about Pioneer own things (e.g. utils) and removed ⚙️ component: Jupiter Issues coming from (internal/official) Jupiter features etc. labels Apr 1, 2024
Michael1993 added a commit that referenced this issue May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants