-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Pass test Method to TestInstanceFactory when using Lifecycle.PER_METHOD #1568
Comments
Related question on StackOverflow: https://stackoverflow.com/q/52108869/14379 |
That's to be expected. As stated in the class-level JavaDoc for
That means that the underlying The In light of that, I don't see any way to provide the test method via the Furthermore, doing so would not align with the design of JUnit Jupiter, namely that class-level extensions should not do anything particular to specific methods. |
FWIW, you may be interested in #878. |
In any case, what I stated above is naturally based on the status quo. It may be technically possible to redesign the internals such that maybe... |
Right, I see.
I'm not sure I understand what you mean by class-level extensions. Perhaps the title of this feature request is too specific in its details (ie TestInstanceFactory), but it would still be useful IMHO, when using PER_METHOD Lifecycle, to be able construct test instances based on method attributes. |
Extensions fall into certain categories depending on where they are applied / when they are invoked. For example, Specifically, So, yeah, I admit: the terminology we use can be rather confusing. In summary, I suppose we could say that extensions are invoked at one of the following levels, where class level and instance level can be somewhat generically grouped under the container level.
What I was trying convey earlier is that we have traditionally not considered that a container-level invocation of an extension would ever have knowledge of anything at the method level (like the test |
Thanks. Given that an instance may be constructed for every method (if PER_METHOD), the levels do seem a bit mixed already. From the outside view, anyway. |
@sbrannen
I am looking for ways how to create additional test class instances and add different parameter dependencies in runtime. Lifecycle.PER_CLASS |
@PaulSh84, please ask your question on Gitter or Stack Overflow. |
Tentatively slated for 5.8 M1 solely for the purpose of team discussion. |
@seanf Is this use case still relevant for you? |
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution. |
This issue has been automatically closed due to inactivity. If you have a good use case for this feature, please feel free to reopen the issue. |
@marcphilipp I don't know if the team is open to re-evaluating this feature request, but here's an example scenario where something like this is useful: quarkusio/quarkus#38336. In a scenario where all fields of a test class are In the case of Quarkus, they allow Since neither the Being able to access the test method to be executed during test instance creation would allow for something like that to be done, while relying purely on constructor injection and not leaving mutable fields around, which works a bit better when using Lombok to apply |
FYI, I created a PR at #4032. The PR was written for #3445, but it would resolve this issue as well. However, since the change of the PR could potentially break existing extensions, more work may be required to provide proper legacy.
The Javadoc only declares where the extension has to be registered, it doesn't say anything about the
I am not sure about that. Extension callbacks are usually executed with the Anyway, that is my perspective on this topic. Feel free to review my pull request. I would say my PR actually reduces the complexity of the production code a bit. However, there is still the problem that it might break existing extensions. |
Please see #3445 (comment). |
Duplicate of #3445 |
I'm trying to update CDI-Unit to support JUnit 5, specifically CDI-Unit's
ProducerConfig
feature for JUnit 4 which uses annotations on the test method to help configure the deployment payload for Weld. Weld is then used to construct test instances. This can almost be replicated in JUnit 5, by implementing aTestInstanceFactory
. (Obviously this won't be compatible withLifecycle.PER_CLASS
, because the instances must allow for per-method configuration.)The problem is, when
TestInstanceFactory.createTestInstance()
is called,extensionContext.getTestMethod()
always returnsOptional.empty()
, even when usingLifecycle.PER_METHOD
.If the
TestInstanceFactory
were to receive the test Method, when usingLifecycle.PER_METHOD
, it would be possible to use annotations from the test method to control test instance creation, thus allowing features likeProducerConfig
to be created.The text was updated successfully, but these errors were encountered: