Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tmurakami committed Aug 4, 2017
1 parent 9295f89 commit a9099b4
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CircleCI](https://circleci.com/gh/tmurakami/dexopener.svg?style=shield)](https://circleci.com/gh/tmurakami/dexopener)
[![Release](https://jitpack.io/v/tmurakami/dexopener.svg)](https://jitpack.io/#tmurakami/dexopener)
[![Javadoc](https://img.shields.io/badge/Javadoc-0.10.3-brightgreen.svg)](https://jitpack.io/com/github/tmurakami/dexopener/0.10.3/javadoc/)<br>
[![Javadoc](https://img.shields.io/badge/Javadoc-0.11.0-brightgreen.svg)](https://jitpack.io/com/github/tmurakami/dexopener/0.11.0/javadoc/)<br>
![Android](https://img.shields.io/badge/Android-4.1%2B-blue.svg)

A library that provides the ability to mock final classes and methods on Android.
Expand Down Expand Up @@ -67,50 +67,28 @@ public class YourAndroidJUnitRunner extends OtherAndroidJUnitRunner {
}
```

By default, mockable final classes and methods are restricted under the package obtained by `Context#getPackageName()`.
Therefore, your tests will fail if using `applicationIdSuffix` in your `build.gradle`.
To change this restriction, you can use `DexOpener.Builder#classNameFilter(ClassNameFilter)` or `DexOpener.Builder#openIf(ClassNameFilter)`.
By default, DexOpener try to load `applicationId + ".BuildConfig"` in order to discover the classes to be opened.
But if the package name of the BuildConfig is not equal to your app's `applicationId`, loading it will fail.
In that case, you should set your app's BuildConfig using `DexOpener.Builder#buildConfig(Class)` like the following code:

```java
public class YourAndroidJUnitRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
DexOpener.builder(context)
.openIf(name -> name.startsWith("package.you.want.to.mock."))
.buildConfig(your.apps.BuildConfig.class)
.build()
.installTo(cl);
return super.newApplication(cl, "your.app.TestApplication", context);
}
}
```

Note that testing might be slow if there are too many classes to be opened.
Normally it would be sufficient to specify your app's root package.

## Limitations

The final classes and methods in the following libraries cannot be mocked.

- [Android](https://developer.android.com/reference/packages.html)
- [Android Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html)
- [Android Data Binding Library](https://developer.android.com/topic/libraries/data-binding/index.html)
- [Android Support Library](https://developer.android.com/topic/libraries/support-library/index.html)
- [Android Testing Support Library](https://developer.android.com/topic/libraries/testing-support-library/index.html)
- [Byte Buddy](http://bytebuddy.net/)
- [ClassInjector](https://github.com/tmurakami/classinjector)
- [Dexmaker](https://github.com/linkedin/dexmaker)
- [DexMockito](https://github.com/tmurakami/dexmockito)
- DexOpener
- [Mockito4k](https://github.com/tmurakami/mockito4k)
- [Hamcrest](https://github.com/hamcrest/JavaHamcrest)
- [JaCoCo](http://www.eclemma.org/jacoco/)
- [JUnit](http://junit.org/)
- [Kotlin](https://kotlinlang.org/)
- [Mockito](http://site.mockito.org/)
- [Objenesis](http://objenesis.org/)

`minSdkVersion` cannot be set to `26` because [dexlib2](https://github.com/JesusFreke/smali) does not currently support version `038` of the DEX format.
- Mockable final classes and methods are restricted under the package of the the app's BuildConfig.
- `minSdkVersion` cannot be set to `26` because [dexlib2](https://github.com/JesusFreke/smali) does not currently support version `038` of the DEX format.

## Notice

Expand Down

0 comments on commit a9099b4

Please sign in to comment.