I'm trying to use a json in an AndroidTestCase, however the JSONObject is always empty, even though I put an element in it. Do I have to do anything special in order to make JSONObjects work in a unit test?
Here's my AndroidTestCase class:
public class JSONUtilTest extends AndroidTestCase {
private JSONObject mJSONSummary;
@Override
public void setUp() throws Exception {
super.setUp();
mJSONSummary = new JSONObject();
mJSONSummary.put("test", 123);
assertTrue(mJSONSummary.length() == 1); //assertion error
}
}
My module's build.grade:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.nubank.brunodea"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
testApplicationId "com.nubank.brunodea"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:22.2.0'
}
I'm using Android Studio 1.2.2 and when I don't use JSONObjects the tests work.
Thanks!