Quantcast
Channel: Using Mockito to mock classes with generic parameters - Stack Overflow
Viewing all articles
Browse latest Browse all 13

Answer by MevlütÖzdemir for Using Mockito to mock classes with generic parameters

$
0
0

The (in my opinion) most easiest and most readable approach is to use method level injection.

This will result in having all test data within the test method. This will keep your test classes clean as there are no 'floating' mock's.

@ExtendWith(MockitoExtension.class)public class SomeClassTest {    @Test    void someTestMethod(@Mock Foo<Bar> fooMock) {        // do something with your mock    }}

Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>