-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Exception using new consumer version selector method in kotlin #1594
Comments
The documentation is wrong, the method needs to be public to be invoked. |
Ah! You created a PR to fix the docs. What a champion! |
Instance methods have one extra parameter, which is the How is your actual test extending the abstract one? |
I need to investigate the JUnit 5 docs, because it looks like it is not providing a test class instance for your test, and I need the instance to be able to call that method on it. |
I did a bit more experimentation about this and added
|
It does work if I unwrap the instance out of the Optional, however I don't know the jUnit5 extension specifics enough in order to understand why the testInstance is missing. In fact, it is already missing on very beginning in Edit: BTW I meanwhile replaced |
For Spring tests, it is better to use |
Looks like this is the old chicken and egg problem. A test instance is created for each interaction to verify, and we need the selectors to fetch the Pacts so we can create the test instances. So when the selector method is called, there will never be a test instance. This is why it needs to be static. The other option is to create an new instance to call with, which will work as long as the selector method does not try to use any test class instance variables. They will not be set. |
I've updated the function, it will support both normal functions, abstract base classes as well as companion objects now. See https://github.com/pact-foundation/pact-jvm/blob/master/provider/junit5/src/test/kotlin/au/com/dius/pact/provider/junit5/ConsumerVersionSelectorKotlinTest.kt |
Awesome, thanks. |
I stumbled over the same issue today, since we also migrating from tags to branches/environments. When can we expect a new release? |
@viktorgt PACT has released the fix tonight. |
Fix confirmed, this code works now:
Thanks a lot for this fast workflow, fix released just 3 days later, that's amazing. |
Thanks for raising! It takes many hands :) |
Hi,
I started to migrate the
@Deprecated
consumerVersionSelectors = [ ]
in the@PactBroker
annotation by the new way, using@PactBrokerConsumerVersionSelectors
method like this. See bottom line:However when running my PactTest that ran using commented-out code above, I get this exception:
I debugged a bit your library and figured, that this line tries to invoke the identified
selectorsMethod
with atestInstance
param that isOptional.empty()
though. I find it strange thatinvokeSelectorsMethod
thinks my selector method has 1 param even though it doesn't. This circumstance is explicitly handled intestClassHasSelectorsMethod
:PactVerificationInvocationContextProvider
What else I tried:
testClassHasSelectorsMethod
even, because its not contained intestClass?.kotlin?.members
:The text was updated successfully, but these errors were encountered: