JUnit testing - question
See original GitHub issueLet’s assume I have a class that has a primary constructor with single parameter (this is required by Android)
class PaymentViewModel(application: Application) : AndroidViewModel(application) {
}
…and now I need to define dependencies using instance()
delegate (I can’t add more parameters to the primary constructor)
class PaymentViewModel(application: Application) : AndroidViewModel(application) {
private val featureEventBus: FeatureEventBus by instance()
}
The question is how to test it?
@RunWith(MockitoJUnitRunner.StrictStubs::class)
class PaymentViewModelTest {
@Mock
private lateinit var mockApplication: Application
@Mock
private lateinit var mockFeatureEventBus: FeatureEventBus
private lateinit var cut: PaymentViewModel
@Before
fun setUp() {
// I want FeatureEventBus property delegate to retrieve
// mockFeatureEventBus instance
cut = PaymentViewModel(mockApplication)
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Top JUnit Interview Questions (2022) - InterviewBit
Open-source unit testing framework for writing test cases. TestNG is similar to JUnit but with extended functionalities. JUnit does not support ...
Read more >Top 23 JUnit Interview Questions (2023) - javatpoint
JUnit Interview Question · 1) What is Testing? · 2) What is JUnit? · 3) What is unit testing? · 4) What is...
Read more >Top 11 JUnit Interview Questions and Answers (2022)
1) Explain what is JUnit? 2) Explain what is Unit Test Case? 3) Explain how you can write a simple JUnit test case?...
Read more >Top 20 JUnit Interview Questions with Answers for Java ...
20+ JUnit [Java Unit Testing] Interview Questions with Answers · 1. What is JUnit? · 2. What is the difference between JUnit 3....
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
Yes but we bring it back for those that don’t want to add the import manually 😃
adding import manually works, so I guess after Kotlin plugin will be fixed this will work properly without
closestKodein