# Kotlin unit test failing when using generics and Mockito

**URL:** <https://discuss.kotlinlang.org/t/kotlin-unit-test-failing-when-using-generics-and-mockito/1866>\
**Category:** Support\
**Created:** [July 14, 2016, 8:46pm UTC](https://discuss.kotlinlang.org/t/kotlin-unit-test-failing-when-using-generics-and-mockito/1866 "2016-07-14T20:46:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![vbezhenar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vbezhenar](https://discuss.kotlinlang.org/u/vbezhenar)\
**Post date:** [July 15, 2016, 3:00am UTC](https://discuss.kotlinlang.org/t/kotlin-unit-test-failing-when-using-generics-and-mockito/1866/2 "2016-07-15T03:00:12Z")

</div>

Add helper function somewhere in your test package:

```auto
inline fun <reified T: Any> mock() = Mockito.mock(T::class.java)

```

and use it instead of Mockito’s:

```auto
val view: View<MyModel> = mock()

```

You can also use the following library which adds this and few other functions to better suit Mockito for Kotlin: [GitHub - mockito/mockito-kotlin: Using Mockito with Kotlin](https://github.com/nhaarman/mockito-kotlin/)

---

_[View the full topic](https://discuss.kotlinlang.org/t/kotlin-unit-test-failing-when-using-generics-and-mockito/1866)._
