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

Add optional constructor arguments support for @InjectMockKs #646

Merged
merged 3 commits into from Jun 30, 2021

Conversation

vladkanash
Copy link

Currently, when using @InjectMockKs annotation with constructor injection, it is required to provide mocked values for all constructor arguments, even if they are optional and have default values (See example below).
With this PR @InjectMockks will still look for mockks for all parameters, including optional, but if nothing is found, default value will be used.

class Example (param1: Param1, param2: Param2 = Param2()) {...}

...

@Mockk
lateinit var param1: Param1

@InjectMockks //Will not work since no mockk for param2 is provided
lateinit var example: Example

@Raibaz
Copy link
Collaborator

Raibaz commented Jun 23, 2021

Nice, thanks a lot for sending this through!

The build failure looks temporary, I'll merge this as soon as it goes green.

@Raibaz Raibaz merged commit 7bf389c into mockk:master Jun 30, 2021
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

Successfully merging this pull request may close these issues.

None yet

3 participants