mocking properties/fields
See original GitHub issueUnfortunately the following doesn’t work:
open class ClassUnderTest ( val property:String )
val mock = mock<ClassUnderTest>()
whenever( mock.property ).thenReturn("value")
assert( mock.property == "value" )
because:
when() requires an argument which has to be ‘a method call on a mock’
I think I understand the root cause of this but it still would be extremely helpful. I think while accessing variables directly is often considered a code smell in Java it is quite common for Kotlin.
Do you see any chance to be able to change that behaviour?
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
Mock Properties | JustMock Documentation - Telerik
Mocking properties is similar to mocking methods, but there are a few cases that need special attention like mocking indexers and particular set...
Read more >Can I mock a class whose fields don't have getter property
How to mock a class who don't have getter properties?. I am new in JUnit and mockito can anyone help me with this?...
Read more >Mocking Public Properties - Docs - Mockery
Mockery allows us to mock properties in several ways. One way is that we can set a public property and its value on...
Read more >Mocking Objects with Restricted Access Members - Wright
In this post, I describe how to create class instances and access/set members from other assemblies when their access levels are set to ......
Read more >Creating Mocks and Spies in Mockito with Code Examples
How to Inject Mocked Dependencies for the Class/Object under Test? ... dependencies which are injected via Constructor or Property fields.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
property
val needs to beopen
as well:The relevant part in the error message:
Nope, Then I started using stubs for the above issue. Also a lot of other testing problems got resolved by using mockk lib.