robolectric-gradle-plugin

How to run a Junit5 test with Android dependencies and robolectric

笑着哭i 提交于 2021-02-07 13:15:45
问题 I am trying to run a unit test like that: @org.junit.jupiter.api.Test void junit5codeCoverage() { final int result = new Foo().junit5(); Assert.assertEquals(Looper.getMainLooper().getThread(), Thread.currentThread()); assertEquals(-1, result); } That is a Junit5 test with Android dependencies (i.e Looper.getMainLooper() ) with Robolectric. I am using the junit5 android plugin from mannodermaus that allows running junit5 within Android setups. But this does not work out of the box because it

“RobolectricTestRunner.class” not recognized in Android Studio

不想你离开。 提交于 2020-12-30 05:36:02
问题 I'm trying to use Robolectric to run unit tests but the Android Studio is not recognizing the class on: @RunWith(RobolectricTestRunner.class) Details: classpath 'com.android.tools.build:gradle:3.0.0' And I'm importing dependency: testImplementation "org.robolectric:robolectric:3.5.1" And: android { testOptions { unitTests { includeAndroidResources = true } } } It simply does not appear option to import the class. Should I add any more dependencies I'm forgetting? Error: error: package org

“RobolectricTestRunner.class” not recognized in Android Studio

空扰寡人 提交于 2020-12-30 05:33:21
问题 I'm trying to use Robolectric to run unit tests but the Android Studio is not recognizing the class on: @RunWith(RobolectricTestRunner.class) Details: classpath 'com.android.tools.build:gradle:3.0.0' And I'm importing dependency: testImplementation "org.robolectric:robolectric:3.5.1" And: android { testOptions { unitTests { includeAndroidResources = true } } } It simply does not appear option to import the class. Should I add any more dependencies I'm forgetting? Error: error: package org

How to add Java 9 to Android Studio?

六眼飞鱼酱① 提交于 2020-05-14 17:51:11
问题 I am using Robolectric library and the latest version of it v4.3.1 requires Java 9 to run. I am trying to point JRE on edit configurations but I am not finding Java 9 in the drop-down even though I have already installed it. It would be really helpful if somebody can please explain! Please check Java 9 installed. 回答1: You can't use Java 9 , Android only supports till Java 8 . You should use the JDK version that comes with Android Studio, NO need for side alone JDK. The current JDK version is

How to add Java 9 to Android Studio?

狂风中的少年 提交于 2020-05-14 17:51:08
问题 I am using Robolectric library and the latest version of it v4.3.1 requires Java 9 to run. I am trying to point JRE on edit configurations but I am not finding Java 9 in the drop-down even though I have already installed it. It would be really helpful if somebody can please explain! Please check Java 9 installed. 回答1: You can't use Java 9 , Android only supports till Java 8 . You should use the JDK version that comes with Android Studio, NO need for side alone JDK. The current JDK version is

How to resolve duplicated gradle Dependency issues

纵饮孤独 提交于 2020-01-31 03:27:07
问题 I have tried to test my code with robolectric. Problem is that it has duplicated References. e.g. java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.apache.maven.artifact.Artifact found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1) I have used the gradel artifact app:dependencies to get the following report. Here the important parts: +--- org.robolectric:robolectric:4

SimpleTestCursor robolectric 3.0— compilation issue

瘦欲@ 提交于 2019-12-31 04:30:10
问题 I am trying to test the cursor in my app. But for the following import I get the error message-- cannot resolve symbol tester. I am using Robolectric 3.0. Why the import is not resolving, am I missing some dependency? I have looked internet but no support. Please help. I am trying to use:this API and following is the import import org.robolectric.tester.android.database.SimpleTestCursor; These are my dependencies: dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile

ClassCastException: NoClassDefFoundError cannot be cast to RuntimeException

旧街凉风 提交于 2019-12-20 18:26:09
问题 I am working on upgrading my codebase to Gradle 2.2 and Android Studio 1.0. I am currently trying to get Robolectric 2.4 working, but I am experiencing a strange issue when I try and run Unit Tests. The issue occurs only after a gradle clean ; running the test suite multiple times will produce passing tests (as expected). When I run the tests after a clean, I get the following error: java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.RuntimeException I

Manifest and setup issues getting Robolectric working with Android Studio 1.1.0

感情迁移 提交于 2019-12-19 17:42:52
问题 I am trying to get Robolectric tests up and working in our current project, and not having a lot of luck. My preference would be to get these to run within Android Studio 1.1.0+. This is my project structure: and here is my test: import android.widget.Button; import com.mycompany.android.app.R; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation

Resources$NotFoundException when running Roboelectric test

删除回忆录丶 提交于 2019-12-18 07:46:19
问题 I've just set up Roboelectric 3.2.2 with a new app and I have written my first simple test: @RunWith(RobolectricTestRunner.class) @Config(manifest="src/main/AndroidManifest.xml", packageName="my.pacakge.name.debug") public class MainActivityTest { @Test public void clickButton() { MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class); String text = ((TextView)mainActivity.findViewById(R.id.text_main)).getText().toString(); assertEquals("Should equal Hello World!", "Hello