Questions tagged [android-junit]

Android testing is based on JUnit. In general, a JUnit test is a method whose statements test a part of the application under test.

History:

For a history of JUnit, visit this Wikipedia page.

About Androids JUnit:

Android's build and test tools assume that test projects are organized into a standard structure of tests, test case classes, test packages, and test projects.

Android testing is based on JUnit. In general, a JUnit test is a method whose statements test a part of the application under test. You organize test methods into classes called test cases (or test suites). Each test is an isolated test of an individual module in the application under test. Each class is a container for related test methods, although it often provides helper methods as well.

In JUnit, you build one or more test source files into a class file. Similarly, in Android you use the SDK's build tools to build one or more test source files into class files in an Android test package. In JUnit, you use a test runner to execute test classes. In Android, you use test tools to load the test package and the application under test, and the tools then execute an Android-specific test runner.

Reference: https://developer.android.com/tools/testing/testing_android.html

Example Questions:

Documentation:

82 questions
3
votes
2 answers

callApplicationOnCreate is called but not newApplication (extending AndroidJUnitRunner)

After setting testInstrumentationRunner "com.example.theapp.utils.CustomAndroidJUnitRunner" in Gradle and in Run/Debug Configurations -> Android Tests -> MyInstrumentedTest -> General -> Specific instrumentation runner (optional) and extending…
3
votes
4 answers

AndroidJUnit4 test not found

I annotated my class like here @RunWith(AndroidJUnit4.class) public class WorkdayProviderTest Futhermore, annotated also my test method like this @Test public void insert_dataInsertsCorrectly() Finally, configured my build.gradle defaultConfig and…
Lemao1981
  • 2,225
  • 5
  • 18
  • 30
2
votes
1 answer

Android unit testing how to test observable and Subscriber

Hi Following is my part of code which I want to test with various requests but I am unable to test as it is observable subscriber patter any idea how to mock subscriber or how to wait for a result in unit testing api.loadData(request) …
amodkanthe
  • 4,345
  • 6
  • 36
  • 77
2
votes
0 answers

Android: Mock a Context for Fragment unit testing

I have a fragment that uses the delegation pattern when a button is clicked. class FutureMeetingEventViewFragment @Inject constructor(): Fragment() { @Inject lateinit var bundleUtilityModule: BundleUtilityModule lateinit var…
Marc Freeman
  • 713
  • 2
  • 7
  • 30
2
votes
1 answer

AndroidJUnit4ClassRunner throwing RuntimeException Android

I am developing an Android app. I am writing the Junit test for the android and I am a novice in the Junit test case. In-app I have one relative layout on click of that I am opening date picker dialog box and once the user selects the date I am…
Harsh Shah
  • 2,162
  • 2
  • 19
  • 39
2
votes
0 answers

Don't fail test if filtering returned no tests in subproject

My connectedDebugAndroidTest fails with com.android.builder.testing.ConnectedDevice > No tests found.[SM-A310F - 7.0] FAILED No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't…
PhilLab
  • 4,777
  • 1
  • 25
  • 77
2
votes
1 answer

Unable to find instrumentation info for: ComponentInfo{../android.support.test.runner.AndroidJUnitRunner}

I have written a simple Android instrumental test case to test networking operation. Test case class name: Main3ActivityTest.java Method name:addNewEmployee I run my test case using command line then I got following exception. Command: ./adb -s…
M.A.Murali
  • 9,988
  • 36
  • 105
  • 182
2
votes
2 answers

Gradle, Android, Jacoco and JUnit5

Now with the release of JUnit 5.0 I'm struggling to get code coverage data using jacoco. My project is multi-module and my problem is that there is no exec file created for each module. Only one in the root project (which seems almost empty). I've…
Alix
  • 2,630
  • 30
  • 72
2
votes
1 answer

Espresso AmbiguousViewMatcherException: How can I select a first horizontal Recyclerview from multiple horizontal Recyclerview

There are multiple horizontal Recyclerview on a screen. I want to perform a espresso click event on first item of first horizontal Recyclerview. Please let me know how we can achieve it. …
2
votes
0 answers

AndroidJUnitRunner and JUnit versions after 4.10

According to AndroidJUnitRunner documentation, The test runner is compatible with your JUnit 3 and JUnit 4 (up to JUnit 4.10) tests Does it mean there are known incompatibilities with 4.11 and 4.12, and if so, what are they? Or was this simply…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
2
votes
3 answers

ImmersiveModeConfirmation with Espresso 2.2.2

Looks like some virtual devices on Google cloud test servers can't execute tests properly because of the Immersive mode confirmation popup (shown here: https://developer.android.com/training/system-ui/immersive.html) - is there a way to…
stef
  • 161
  • 1
  • 10
2
votes
1 answer

ServiceTestRule#startService timeout for unbound services

I am being faced with this issue, basically the ServiceTestRule throws a TimeoutException when startService is called in an unbound services, and would like to know if someone knows of a possible workaround until a fix is released? The unbound…
Luís Ramalho
  • 10,018
  • 4
  • 52
  • 67
2
votes
0 answers

Mock Account Manager with AndroidJUnit4

I have an Activity that calls AccountManager.get(this) giving me an instance of the AccountManager to call getAuthTokenByFeatures(). I want to test this activity and mock the different responses that the Account manager could give me. Using the…
MungoRae
  • 1,912
  • 1
  • 16
  • 25
2
votes
1 answer

Timeout for AndroidJUnitRunner + ActivityInstrumentationTestCase2?

The setup: An older project I've inherited has a lot of legacy instrumentation tests and I would like to impose a timeout on them, since a lot of them can hang indefinitely and this makes it hard to get a test report. I'm in the process of updating…
Turnsole
  • 3,422
  • 5
  • 30
  • 52
2
votes
1 answer

AndroidJUnit4.class not found on Instrumentation tests

I'm having trouble with AndroidJunit4.class import. I created the test class in the androidTest/java/ folder but it seems that the class is not found. Even if I force the right import it still doesn't work. ( import…
rct29
  • 21
  • 3