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
1
vote
0 answers

Any batter custom solution for retry failed test cases in android espresso

Suggest any solution in kotlin or java for retry 1 or 2 times only failed test case Tried many solution but does not work any properly
1
vote
1 answer

How to write junit test for object class in kotlin/android?

Maybe this is very basic question but could not find anything online. I have created a object class in kotlin contains few methods. I am calling those from ViewModel and I have written junit test case for ViewModel where object class instance is…
VVB
  • 7,363
  • 7
  • 49
  • 83
1
vote
1 answer

mockito, how to coverage test the catch block

Android app, Having a function calling another function, that function may throw static string SOME_DEFINE_1 = "some_define_1"; ...... void myFunc() { try { HashMap data = new HashMap<>(); …
lannyf
  • 9,865
  • 12
  • 70
  • 152
1
vote
1 answer

Collect JUnit Test Metadata via Annotations

Is there a class/method I could implement within JUnit that is basically a "hook" that runs after each test case finishes, with user-defined (in code) metadata available? I'm trying to accomplish something like this: Annotate a test case with a…
Dragan R.
  • 598
  • 4
  • 18
1
vote
1 answer

How to test ContentProvider with ProviderTestRule in kotlin

I have implemented a ContentProvider that uses a Room database to store the data. The implementation is done in kotlin and it follows the same pattern shown in this Google example. The ContentProvider works fine when used in an app. Now I want to…
1
vote
0 answers

ClassNotFoundException on IntrumentationRegistry while running Test

I have a utility class in my application that saves the User data from the server onto the SharedPreferences. I was trying to test the utilty class which is named UserLocalStore.kt I wrote the following test class to do…
ravi
  • 899
  • 8
  • 31
1
vote
1 answer

How do I use an ActivityTestRule with @ClassRule in Kotlin?

I suspect my question is the same as this one, but the code there is incomplete and I must be missing something. Here's my test class: @RunWith(AndroidJUnit4::class) class MyTest { companion object { @ClassRule @JvmField …
1
vote
0 answers

Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)"

I am trying to creating a privileged apk and have updated my Android.mk to set the privilege module to true. My apk is compiled on a linux build and not using Android Studio. I also have the following in my Test Code When I push my apk to target and…
Hars13
  • 11
  • 2
1
vote
1 answer

Test Orchestrator Sample

Is anyone aware of a sample project that shows how to get test orchestrator working? I checked the google samples and there doesn't seem to be a good sample project that shows test orchestrator. https://github.com/googlesamples/android-testing I…
Jon
  • 1,381
  • 3
  • 16
  • 41
1
vote
1 answer

How to assert that multiple variables have the same value?

I'm writing a jUnit test for a calculation function double calculate(double val1, double val2); The function is expected to return the same result if the inputs are "flipped", i.e. it shouldn't matter which one comes first, and it shouldn't matter…
Magnus
  • 17,157
  • 19
  • 104
  • 189
1
vote
2 answers

Android prob with AndroidJUnitRunner giving 'java.lang.ClassNotFoundException'

I am new in Instrumentation testing. I am trying basic testing with AndroidJUnitRunner. Here is my gradle: apply plugin: 'com.android.application' android { compileSdkVersion 24 buildToolsVersion "25.0.0" defaultConfig { …
1
vote
1 answer

Mocking dependency error with AndroidJunitRunner and Dagger2

I am trying to mock dependencies like what is suggested in https://artemzin.com/blog/how-to-mock-dependencies-in-unit-integration-and-functional-tests-dagger-robolectric-instrumentation/ Unfortunately I can't get past the following error when I run…
Eric
  • 781
  • 1
  • 10
  • 18
1
vote
0 answers

Android & AndroidJUnit4. How to handle & test indeterminate lifecycle loop error

Errors connected with infinite loops of view events are the topic of this question. Such loops don't throw StackOverflowError, because are executed very frequently, but not recursively. An example of that code error could be invalidate() call inside…
Beloo
  • 9,723
  • 7
  • 40
  • 71
1
vote
2 answers

can't run espresso test

I'm using Espresso to run android UI test, after including all the required dependencies and create the required class test, when running it give me the error: java.lang.Exception: Custom runner class AndroidJUnit4 should have a public constructor…
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
1
vote
1 answer

Mocking presenter cause integration test to dump

Recently i've started covering my project with integration tests where mockito provides presenter instances to verify whether or not my views calling presenter methods properly during their events. The issue was on the screen which has invisible…
Beloo
  • 9,723
  • 7
  • 40
  • 71