AndroidJunit4.class runner in Android Studio does not call @Test methods

I applied the following instructions: https://code.google.com/p/android-test-kit/wiki/AndroidJUnitRunnerUserGuide to configure JUnit4 tests.

In particular, I follow the instructions for using Junit4 with ActivityInstrumentationTestCase2, however, when I run tests in Android Studio, the annotated @Test methods do not execute. If I prefix methods with 'test', this works, but that is not what I expect for JUnit 4 tests.

Has anyone encountered this issue?

Hi,

+5
source share
4 answers

There is no need to extend ActivityInstrumentationTestCase2 . If you need access to an Activity , an ActivityTestRule exists in the test support libraries. Instead of extending ActivityInstrumentationTestCase2 you can now do:

 @RunWith(AndroidJUnit4.class) public final class ActivityTest { @Rule public final ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class); @Test public void useActivityInTest() { Activity activity = activityTestRule.getActivity(); } } 
+6
source

I found that I had to add one test method, for example:

 public void test() {} 

Then all my real tests are annotated with @Test

+2
source

Fixed if specified in the tester's app / build.gradle file:

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

 defaultConfig { applicationId "com.domain.appname" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } 
+2
source

I encountered this error when trying to run a separate test method in Android Studio (by right-clicking and selecting it from the context menu), and not the entire class.

Running the whole class made the test work as expected.

0
source

Source: https://habr.com/ru/post/1212866/


All Articles