我有一個應用程序,我正在爲它編寫單元測試用例。
我的測試情況給予警告,巨大的名單和1個錯誤
跟着下面的鏈接和子頁Building Instrumented Unit TestsInstrumented Android單元測試和ProGuard
錯誤和一些警告
Warning:there were 10 unresolved references to classes or interfaces. You may need to add missing library jars or update their versions. If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass) Warning:there were 5 instances of library classes depending on program classes. You must avoid such dependencies, since the program classes will be processed, while the library classes will remain unchanged. (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency) Warning:there were 3 unresolved references to program class members. Your input classes appear to be inconsistent. You may need to recompile the code. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember) Warning:Exception while processing task java.io.IOException: Please correct the above warnings first. :app:transformClassesAndResourcesWithProguardForDebugAndroidTest FAILED
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebugAndroidTest'. java.io.IOException: Please correct the above warnings first.
如果我從調試刪除ProGuard的,我得到64K錯誤!
Error:The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
我在做什麼錯?
應用的build.gradle
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.tyagiabhinav.xyz"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies
{
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:support-annotations:24.2.0'
......
androidTestCompile 'com.android.support:support-annotations:24.2.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
測試Java類
package com.tyagiabhinav.xyz;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import com.tyagiabhinav.xyz.Util.PrefHelper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Created by abhinavtyagi on 24/08/16.
*/
@RunWith(AndroidJUnit4.class)
public class PrefTester {
Context mMockContext;
private PrefTester() {
super();
}
@Before
public void setUp() {
mMockContext = InstrumentationRegistry.getTargetContext();
PrefHelper.init(mMockContext);
}
@Test
public void testSharedPref(){
Assert.assertEquals(false,PrefHelper.isLoggedIn());
}
}
如果我刪除了proguard,我收到64k錯誤。我的代碼不是很大。這是一個小應用程序。但在編寫這個測試用例之後,我在編譯時看到64k錯誤。 –