android-espresso

Android Espresso test: Class not found: …Empty test suite

本小妞迷上赌 提交于 2020-12-31 05:56:07
问题 I'm trying to implement things from this example - https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSample - into my app. When I try to execute the simple Espresso test, this happens: "/Applications/Android Studio 2.2.3.app/Contents/jre/jdk/Contents/Home/bin/java" (...) Process finished with exit code 1 Class not found: "com.faces_shop.app.MainActivityTest"Empty test suite. (copy-pasted from Android Studio) The test: package com.faces_shop.app; import android

How to correctly mock ViewModel on androidTest

别等时光非礼了梦想. 提交于 2020-12-29 05:24:05
问题 I'm currently writing some UI unit tests for a fragment, and one of these @Test is to see if a list of objects is correctly displayed, this is not an integration test, therefore I wish to mock the ViewModel . The fragment's vars: class FavoritesFragment : Fragment() { private lateinit var adapter: FavoritesAdapter private lateinit var viewModel: FavoritesViewModel @Inject lateinit var viewModelFactory: FavoritesViewModelFactory (...) Here's the code: @MediumTest @RunWith(AndroidJUnit4::class)

How to correctly mock ViewModel on androidTest

空扰寡人 提交于 2020-12-29 05:23:19
问题 I'm currently writing some UI unit tests for a fragment, and one of these @Test is to see if a list of objects is correctly displayed, this is not an integration test, therefore I wish to mock the ViewModel . The fragment's vars: class FavoritesFragment : Fragment() { private lateinit var adapter: FavoritesAdapter private lateinit var viewModel: FavoritesViewModel @Inject lateinit var viewModelFactory: FavoritesViewModelFactory (...) Here's the code: @MediumTest @RunWith(AndroidJUnit4::class)

Assert exceptions in Android Espresso test

半城伤御伤魂 提交于 2020-12-12 05:43:06
问题 I have a test in Espresso that needs to assert that a certain action cause an exception to be thrown. However it seems that the Espresso framework swallows the original exception and only surfaces a PerformException . 回答1: Eventually I found a way to do it. I've created a custom Hamcrest matcher that allows you to verify a nested exception. public class NestedExceptionMatcher extends TypeSafeMatcher<Throwable> { private final Class<?> mExpectedType; private final Matcher<String>

Assert exceptions in Android Espresso test

纵饮孤独 提交于 2020-12-12 05:42:31
问题 I have a test in Espresso that needs to assert that a certain action cause an exception to be thrown. However it seems that the Espresso framework swallows the original exception and only surfaces a PerformException . 回答1: Eventually I found a way to do it. I've created a custom Hamcrest matcher that allows you to verify a nested exception. public class NestedExceptionMatcher extends TypeSafeMatcher<Throwable> { private final Class<?> mExpectedType; private final Matcher<String>