Questions tagged [robolectric-gradle-plugin]

The robolectric-gradle-plugin is a plugin for Gradle that allows Android Gradle builds to run Robolectric style tests.

The robolectric-gradle-plugin is a plugin for Gradle that allows Android Gradle builds to run Robolectric style tests.

It was originally authored by Jake Wharton and is available from Maven central.

77 questions
42
votes
1 answer

Robolectric unit tests fail after Multidex

So I recently merged my robolectric 3.0 upgrade with our mainline, which had added multidex support to our application. Unfortunately, this had the unfortunate side effect of causing our tests to fail/not run - they'd simply stop after the first…
23
votes
4 answers

How to resolve duplicated gradle Dependency issues

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…
finder2
  • 842
  • 1
  • 11
  • 30
21
votes
5 answers

"RobolectricTestRunner.class" not recognized in Android Studio

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…
18
votes
3 answers

ClassCastException: NoClassDefFoundError cannot be cast to RuntimeException

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;…
16
votes
6 answers

How to add Java 9 to Android Studio?

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. Please check Java 9…
15
votes
2 answers

How to run a Junit5 test with Android dependencies and robolectric

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()); …
joecks
  • 4,539
  • 37
  • 48
11
votes
5 answers

Android Studio + Robolectric + Gradle Class Not Found Exception

I downloaded Robolectric deckard-gradle project from https://github.com/robolectric/deckard-gradle and imported to Android Studio. On my first run i got !!! JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub! at…
savepopulation
  • 11,736
  • 4
  • 55
  • 80
10
votes
2 answers

How to run unit test on a android module?

I have a android project that has multiple library modules and I am trying to test a specific package that contains all modules. I tried this command: ./gradlew -Dtest.single=com.moduleone* testProductionDebug And it does not work: it doesn't…
Jono
  • 17,341
  • 48
  • 135
  • 217
10
votes
1 answer

How to use findViewById() in robolectric

I simply want to test with robolectric if a certain view is visible in a fragment. My unit test looks like this: ActivityController controller = Robolectric.buildActivity(FragmentActivity.class); FragmentActivity activity = (FragmentActivity)…
9
votes
2 answers

some Robolectric tests fail when run all together but pass individually

I'm on Android Studio 1.2, Robolectric 3.0-rc2. I have two test classes, one called MotdTest with one test method that tests for POJO json serialization & deserialization. The other is called UserInfoTest, which contains 4 test methods that tests…
waynesford
  • 1,688
  • 19
  • 17
8
votes
4 answers

Robolectric test hangs up when started - Transferring from sonatype

I have a problem with configuring Robolectric in my project. I am also using Kotlin, if it matters. Here is my build.gradle apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { compileSdkVersion…
7
votes
2 answers

Resources$NotFoundException when running Roboelectric test

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…
6
votes
1 answer

The Robolectric-Tests case errors with Room-library(arch-component)

java.lang.AssertionError: Error(s) present: [java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[RxCachedThreadScheduler-8,5,main] []] (latch = 0, values = 0, errors = 1, completions = 0) I use Room to…
6
votes
2 answers

I am studying Robolectric but an error occured

I am studying Robolectric. My project dir is, My unit test codes MainActivityTest are as follows, package com.example.activity; import android.app.Activity; import com.example.BuildConfig; import org.junit.Test; import…
kidoher
  • 2,297
  • 2
  • 12
  • 19
6
votes
1 answer

android.content.res.Resources$NotFoundException in Robolectric 2.4

I have trouble loading resources when running unit tests from command line. It works fine in IntelliJ. I'm using: com.android.tools.build:gradle:1.1.3 org.robolectric:robolectric-gradle-plugin:1.0.1 org.robolectric:robolectric:2.4 I have the…
Alix
  • 2,630
  • 30
  • 72
1
2 3 4 5 6