Writing instrumentation tests for the first time w...
# dagger
s
Writing instrumentation tests for the first time with HILT and the tests don't run at all. Adding screenshots and code for context :
Copy code
@SmallTest
@HiltAndroidTest
class ExpenseDaoTest {
    @get:Rule
    var hiltRule = HiltAndroidRule(this)

    @get:Rule
    var instantTaskExecutorRule = InstantTaskExecutorRule()

    @Inject
    @Named("test_db")
    lateinit var database: IOUDatabase
    private lateinit var expenseDao: ExpenseDao

    @Before
    fun setup() {
        hiltRule.inject()
        expenseDao = database.expenseDao()
    }

    @After
    fun tearDown() {
        database.close()
    }

    @Test
    fun insertExpense() =
        runBlockingTest {
            val expense = ExpenseCacheEntity(
                id = "1",
                title = "Dosa",
                date = LocalDate.now(),
                amount = 100.00,
                description = "",
                paid_by = arrayListOf("1A"),
                split_with = arrayListOf("1A", "2B")
            )

            expenseDao.insertExpense(expense)
            val getExpense = expenseDao.getExpenseById("1")
            assertTrue(getExpense.id == expense.id)
        }
}
Any idea how to get across this? Been struggling for more than a day.
w
This usually happens when some part of the test setup crashes. Do you see any logs in logcat when running the tests? There’s good chance there’ll some stacktrace from the app pointing out what goes wrong
1
s
Got it! Pretty noob mistake tbh. The path to my
HiltTestRunner
class was incorrect (build.gradle). Thanks @wasyl 🙂
👍 1