• Stars
    star
    317
  • Rank 131,836 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Gradle plugin to be used in combination with the new unit testing feature of the Gradle Plugin / Android Studio to use real classes for e.g. SparseArray.

Android Unmock Gradle Plugin

Purpose

This is a super simple plugin to be used in combination with the new unit testing feature of the Gradle Plugin / Android Studio. ( http://tools.android.com/tech-docs/unit-testing-support )

It tries to solve the problem that you have to mock each and every Android SDK class (even SparseArray, TextUtils etc.) by allowing you to use selected classes from a real Android-Jarfile.

How to use

Add the plugin to your buildscript dependencies and make sure to use the maven central repository:

buildscript {
    repositories {
        mavenCentral()
    }
    
    dependencies {
        classpath 'com.github.bjoernq:unmockplugin:0.7.9'
    }
}

Please note: Versions prior to 0.7.6 are not available on Maven Central.

And this to the module's build script:

apply plugin: 'de.mobilej.unmock'

Additionally you have to configure which classes to use and where to get the real Android.jar from. e.g:

unMock {
    keep "android.widget.BaseAdapter"
    keep "android.widget.ArrayAdapter"
    keep "android.os.Bundle"
    keepStartingWith "android.database.MatrixCursor"
    keep "android.database.AbstractCursor"
    keep "android.database.CrossProcessCursor"
    keepStartingWith "android.text.TextUtils"
    keepStartingWith "android.util."
    keepStartingWith "android.text."
    keepStartingWith "android.content.ContentValues"
    keepStartingWith "android.content.ComponentName"
    keepStartingWith "android.content.ContentUris"
    keepStartingWith "android.content.ContentProviderOperation"
    keepStartingWith "android.content.ContentProviderResult"
    keepStartingWith "android.content.UriMatcher"
    keepStartingWith "android.content.Intent"
    keep "android.location.Location"
    keepStartingWith "android.content.res.Configuration"
    keepStartingWith "org."
    keepStartingWith "libcore."
    keepStartingWith "com.android.internal.R"
    keepStartingWith "com.android.internal.util."
    keep "android.net.Uri"

    keepAndRename "java.nio.charset.Charsets" to "xjava.nio.charset.Charsets"
}

dependencies {
    // dependency to android-all to use
    unmock 'org.robolectric:android-all:4.3_r2-robolectric-0'
}
Statement Description
keep keeps the specified class (and it's possibly present inner classes)
keepStartingWith keeps every class which FQN starts with the given string
keepAndRename let you keep a class while renaming it (e.g. needed for classes in the "java" top-level package since these are only allowed to be loaded from the boot classpath)
delegateClass every method (and constructor) in the given class is delegated to de.mobilej.ABridge. Makes it easier to mock things in a framework class you inherit from

That's it!

Have a look at the example contained in this repository for more details.

Starting from version 0.3.5 you can leave out the configuration closure which will result using defaults (which are shown in the example above).

If you use any of the keep statements the default configuration will be cleared. (So your own configuration is not adding but replaces the default).

If you don't configure the unmock dependency the plugin will use org.robolectric:android-all:4.3_r2-robolectric-0

Versions

Version Description
0.1.0 initial public release
0.1.1 added the '-' matching
0.1.2 fixed a bug preventing the plugin to work correctly on Windows systems
0.1.3 the binary is targeting Java 1.7, again
0.2.0 support class renaming, rebuild jar if build file changed
0.3.0 use Gradle way of upToDate check, have a DSL for the configuration
0.3.1 compile with Gradle 2.4
0.3.2 lib-sample and some bugfixes (frozen class problem)
0.3.3 Android Gradle Plugin 1.3.0 compatibility
0.3.5 Use default config if no configuration closure is given
0.3.6 Optionally you can specify a directory to download the all-android.jar to
0.4.0 Support for "delegateClass" added
0.5.0 ABridge now includes callByte, callDouble and callFloat, this might break tests that rely on ABrdige.callObject to be called in these cases
0.5.1 Unique names for unmocked-android.jar to workaround an Android Studio problem
0.6.0 Use Gradle's dependency management to get the android-all.jar, more magic to workaround issues using unmocked Android-6.0+ classes
0.6.1 Make it work with Gradle 4.0-milestone and Android Gradle plugin to 3.0.0.-alpha1 while keep it working on previous versions
0.6.2 Make it work with activated Kotlin plugin
0.6.3 Make it possible to use Gradle 4 with Android Gradle plugin < 3.0
0.6.4 Works with kapt3
0.6.5 Also copy non-class files when they are matched by keepStartingWith
0.7.0 Using downloadFrom will make your build fail - use unmock scoped dependency now
0.7.1 Add support for proper Gradle up-to-date checks (thanks to @drewhannay)
0.7.2 Enable relocatable Gradle build cache support (thanks to @drewhannay)
0.7.3 Several internal improvements (PR 52, 53) contributed by @drewhannay and @stephanenicolas
0.7.4 Bump Javassist version
0.7.5 Allow unmocked classes in any variant (PR 62)
0.7.6 Bump Javassist version to 3.27.0-GA
0.7.7 ---
0.7.8 Gradle 7.0 compatability, contributed by @calvarez-ov
0.7.9 Fix #77, contributed by @matejdro

License

Copyright 2015,2016,2017,2018,2019,2020,2021 Björn Quentin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

thinr

An easy to use AsyncTask replacement - life cycle aware and leak preventing
Java
114
star
2

esp32-rust-nostd-temperature-logger

MQTT temperature logger running on ESP32 in Rust (no-std / no RTOS)
Rust
36
star
3

adc

An Android Studio plugin to control your development devices and emulators. Currently you can do the following from within your IDE:
Java
25
star
4

bl602-wifi-rs

WIP / POC for using the BL602 wifi blob from Rust for wifi and BLE connectivity
Rust
23
star
5

esp32c3-ota-experiment

ESP32-C3 Bare Metal OTA Experiment
Rust
22
star
6

svd2html

A simple script (in Rust lang) to create HTML from SVD
Rust
15
star
7

bleps

A toy-level BLE peripheral stack
Rust
13
star
8

esp32c3-rust-std-temperature-logger

MQTT temperature logger running on ESP32C3 in Rust (std)
Rust
12
star
9

rust_azure_sphere_advanced

Sample using Rust on Azure Sphere with Networking and Multi-Threading
Rust
11
star
10

blash

A tool to flash BL602 via JTAG + serial without pressing buttons / setting jumpers
Rust
10
star
11

bluepet

A PET 2001 emulator on STM32F103 (BluePill)
Rust
9
star
12

bare-matter

Rust
8
star
13

air602_rust

A basic hello world app for the Air602 wifi module written in Rust
Python
6
star
14

esp-bare-matter

Rust
5
star
15

ps2keyboard-esp32c3

ESP32-C3 interfacing to a PS/2 Keyboard (bare-metal Rust)
Rust
4
star
16

esp32c3-sleep-experiment

Experimenting with sleep on ESP32-C3 in bare-metal Rust
Rust
4
star
17

whitemagic

An easy way to do lifecycle aware async task style thing on Android with Kotlin
Kotlin
3
star
18

matter-rs-experiment

Rust
3
star
19

mksettings

Rust
3
star
20

mini-rv32ima-rs

Simple Rust port of mini-rv32ima
Rust
2
star
21

rust_azure_sphere_blinky

Using Rust to develop Blinky (the "Hello World" of embedded) for Azure Sphere
Rust
2
star
22

ssize

Show function's stack-size
Rust
2
star
23

measure-current

INA219 and ESP32-C3 / bare-metal Rust
Rust
2
star
24

esp32-ulp-rust-macro

Rust
2
star
25

puny-tls

A no-std / no-alloc TLS 1.3 client
Rust
2
star
26

kmockit

Kotlin friendly wrapper for JMockit
Kotlin
2
star
27

espsegs

Rust
2
star
28

rconfig

Rust
2
star
29

IntelliJJUnitPatcher

Android Studio Plugin to enable you running standard Java-JUnit tests in the JVM (using robolectric-gradle-plugin)
Java
2
star
30

twatch-bare-metal

Rust
1
star
31

i2c-dummy-device

ESP32-C3 as I2C dummy device
Rust
1
star
32

ble-hci

Work in progress minimal BLE peripheral stack
Rust
1
star
33

esp-hal-get-started

mdBook: Getting Started with bare-metal Rust on ESP32
1
star
34

esp32c3-preemt-experiment

Rust
1
star
35

ps2keyboard-esp32

ESP32 interfacing to a PS/2 Keyboard (bare-metal Rust)
Rust
1
star
36

esp32c3-dhcp-experiment

ESP32-C3 bare-metal captive portal example / experiment
Rust
1
star
37

rust-esp32s3-ili9341

Rust
1
star
38

s3box-sound

Rust
1
star
39

bleps-esp32-rust-std

Using bleps BLE stack on ESP32 in Rust STD
Rust
1
star